Learn R Programming

ggautomap

ggautomap provides {ggplot2} geometries that make use of {cartographer}, a framework for matching place names with map data. With ggautomap your input dataset doesn’t need to be spatially aware: the geometries will automatically attach the map data (providing it’s been registered with {cartographer}).

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

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")

Copy Link

Version

Install

install.packages('ggautomap')

Monthly Downloads

128

Version

0.3.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Carl Suster

Last Published

May 24th, 2023

Functions in ggautomap (0.3.2)

stat_automap

Attach spatial data with 'cartographer'
stat_automap_coords

Attach coordinates with 'cartographer'
coord_automap

Specify an inset configuration for the whole plot
geom_geoscatter

Place points randomly or in a grid within locations
configure_inset

Configure transformations underpinning a map inset
crs_eqc

Coordinate reference system for spatial computations
ggautomap-package

Create Maps From a Column of Place Names
reexports

Objects exported from other packages
geom_choropleth

Associate regions with counts
position_circle_repel

Pack overlapping points into a circle
geom_centroids

Geographic centroid of locations
geom_boundaries

Map feature boundaries