cartographr

Crafting print-ready maps and layered visualizations in R using OpenStreetMap and simple features.

https://github.com/da-wi/cartographr

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (20.2%) to scientific vocabulary
Last synced: 9 months ago · JSON representation

Repository

Crafting print-ready maps and layered visualizations in R using OpenStreetMap and simple features.

Basic Info
Statistics
  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created over 3 years ago · Last pushed 10 months ago
Metadata Files
Readme Changelog License

README.Rmd

---
output:
  md_document:
    variant: gfm
---



```{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/",
  warning = FALSE
)
```

# cartographr 

[![R-CMD-check](https://github.com/da-wi/cartographr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/da-wi/cartographr/actions/workflows/R-CMD-check.yaml)
[![codecov test
coverage](https://codecov.io/gh/da-wi/cartographr/branch/develop/graph/badge.svg)](https://app.codecov.io/gh/da-wi/cartographr?branch=develop)

## Overview

Creating maps from OpenStreetMap data can be complex and time-consuming due to varying design syntax and the challenge of producing visually appealing, print-ready maps. Overlaying additional information layers while maintaining cartographic aesthetics also requires a deep understanding of spatial data. `cartographr` addresses these issues by providing a lightweight, user-friendly interface between `osmdata` and `ggplot2`, streamlining the map-making process and allowing users to focus on the narrative of their maps. It simplifies the transformation of geospatial data using simple features (`sf`) geometries into informative, high-quality visualizations, enhancing the dissemination of spatial information. Ideal for urban planning, environmental studies, or public presentations, `cartographr` aims to make map creation straightforward and effective.

## Installation

Simply install from github.

```{r eval=FALSE}
# Install the latest version from github
devtools::install_github("da-wi/cartographr")

# Alternatively, install from CRAN
install.packages("cartographr")
```

## Usage

Begin by determining the central point of your map using the [WGS84](https://de.wikipedia.org/wiki/World_Geodetic_System_1984) coordinates. For our example, we’ll use Vienna’s center with a latitude of `48.210` and a longitude of `16.370`. You can easily find these coordinates online.

Decide on the size of the printed map, such as A4. This will help scale the text and lines on the map proportionally, no matter the print size.

```{r eval=FALSE}
set_output_size(c(300,300))
```

Use the `get_osmdata()` function to collect OpenStreetMap data. Set the width of your map area in meters using the `x_distance` parameter. If you leave out the height (`y_distance`), it will be calculated based on the width and the aspect ratio of your chosen output size.


```{r eval=FALSE}
osm <- get_osmdata(48.210, 16.370, x_distance = 1200)
```

The `osm` variable now contains all the geometric shapes (like buildings, rivers, parks) that will appear on your map. Generate the map with `plot_map()` and customize its look with themes and color palettes. For instance, create an infomap of Vienna using `theme_infomap()` and choose a color scheme (see `get_palette()`).

```{r eval=FALSE}
plot_vienna <- osm |> plot_map(palette = "serene") +
  theme_infomap() +
  ggplot2::labs(title = "VIENNA")
```

To view your map, simply call

```{r eval=FALSE}
plot_vienna
```



```{r eval=FALSE, include  = FALSE}
ggsave(plot_vienna + theme(plot.title = element_text(size = 60)), filename = "png/vienna.png", device = "png",width = 300,height = 300, units = "mm", dpi = 96, bg = "white" )
```

```{r echo=FALSE,include=FALSE,fig.align='center', fig.cap='',fig.dim=c(2.5,2.5), out.width='70%'}
# knitr::include_graphics('vienna.png')
```

Finally, save your map as a PDF file, ready for printing.

```{r eval=FALSE}
save_map(plot = plot_vienna, filename="vienna.pdf")
```

## Palette overview

Several color palettes are provided by the package, however, you can easily create and use your own palette (see `get_palette()`).

```{r set environment, include=F, eval=FALSE}
set_output_size(c(160,160))
set_attribution(FALSE)
```


```{r load osm, eval=F}
hamburg <- get_osmdata(lat = 53.545, lon = 10.000, x_distance = 1200)

df_pal <- tibble (palettes= c("alphabet", "arctic","autumn", "bw",
                        "evening", "gray", "iberia", "imhof","lines","midnight",
                        "minimal","metropolitan","serene","swiss","tropical"),
                  hamburg = list(hamburg)) |>
  rowwise() |>
  mutate(p = list(hamburg |> plot_map(palettes) + theme_infomap() + labs(title = palettes)))
```


```{r plot palettes, echo = FALSE, eval = FALSE, results='hide',fig.keep='all', fig.dpi=72, fig.dim=c(6,6), out.width="100%"}
df_pal |> pull(p)
```


```{r save figures, eval = F, include = FALSE}
df_pal |> ungroup() |> mutate(i = row_number(), filename = sprintf("png/plot palettes-%d.png",i)) |> rowwise() |> mutate(res = ggsave(p + theme(plot.title = element_text(size = 60)), filename = sprintf("png/plot palettes-%d.png",i), device = "png",width = 160,height = 160, units = "mm", dpi = 112))
```





## Data licensing All data that you access using `cartographr` and, in consequence, `osmdata` is licensed under OpenStreetMap’s license, the Open Database Licence. Any derived data and products must also carry the same licence. You should make sure you understand that licence before publishing any derived datasets. ## Getting help If you encounter a clear bug, please file an issue with a minimal reproducible example on GitHub. ## Credits The development of this project drew inspiration from the [prettymaps](https://github.com/marceloprates/prettymaps) project.

Owner

  • Login: da-wi
  • Kind: user
  • Location: Krems, Austria
  • Company: Karl Landsteiner University of Health Sciences

GitHub Events

Total
  • Issues event: 2
  • Delete event: 1
  • Issue comment event: 1
  • Push event: 4
  • Pull request event: 1
Last Year
  • Issues event: 2
  • Delete event: 1
  • Issue comment event: 1
  • Push event: 4
  • Pull request event: 1

Issues and Pull Requests

Last synced: 10 months ago

Packages

  • Total packages: 1
  • Total downloads:
    • cran 283 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 2
  • Total maintainers: 1
cran.r-project.org: cartographr

Crafting Print-Ready Maps and Layered Visualizations

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 283 Last month
Rankings
Dependent packages count: 28.6%
Dependent repos count: 35.3%
Average: 50.1%
Downloads: 86.5%
Maintainers (1)
Last synced: 10 months ago

Dependencies

.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action v4.5.0 composite
  • actions/checkout v4 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION cran
  • dplyr * imports
  • ggplot2 * imports
  • lwgeom * imports
  • osmdata * imports
  • sf * imports
  • showtext * imports
  • sysfonts * imports
  • tibble * imports
  • ggpubr * suggests
  • knitr * suggests
  • rmarkdown * suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v4 composite
  • actions/upload-artifact v4 composite
  • codecov/codecov-action v4 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite