ggautomap

ggautomap status badge R-CMD-check

ggautomap helps when you have a spreadsheet/table of data that includes a column of place names, and you want to visualise that data on a map. It saves you from having to think about geospatial libraries when all you want to do is make a quick plot from your spreadsheet.

See the ‘Getting started’ article, vignette("ggautomap"), for some recipes for different types of plots it can make.

ggautomap works best if:

ggautomap might not be right for you if …

In most of these cases, you should instead use a combination of {sf}, ggplot2::geom_sf(), and possibly {cartographer} to have more direct control. If you just want the map insets from the vignette, see {ggmapinset}.

Installation

You can install ggautomap like so:

# CRAN release
install.packages('ggautomap')

# development version
install.packages('ggautomap', repos = c('https://cidm-ph.r-universe.dev', 'https://cloud.r-project.org'))

Example

Let’s use the example dataset from {cartographer}:

library(cartographer)

head(nc_type_example_2)
#>      county type
#> 1    MARTIN    A
#> 2  ALAMANCE    B
#> 3    BERTIE    A
#> 4   CHATHAM    B
#> 5   CHATHAM    B
#> 6 HENDERSON    B

A possible workflow is to use cartographer::add_geometry() to convert this into a spatial data frame and then use ggplot2::geom_sf() to draw it.

ggautomap instead provides geoms that do this transparently as needed, so you don’t need to do a lot of boilerplate to wrangle the data into the right form before handing it off to the plotting code.

library(ggplot2)
library(ggautomap)

ggplot(nc_type_example_2, aes(location = county)) +
  geom_boundaries(feature_type = "sf.nc") +
  geom_geoscatter(aes(colour = type), size = 0.5) +
  coord_automap(feature_type = "sf.nc")

ggplot(nc_type_example_2, aes(location = county)) +
  geom_choropleth() +
  geom_boundaries(feature_type = "sf.nc") +
  scale_fill_steps(low = "#e6f9ff", high = "#00394d", na.value = "white") +
  coord_automap(feature_type = "sf.nc")