Learn R Programming

geofacet

This R package provides geofaceting functionality for ggplot2. Geofaceting arranges a sequence of plots of data for different geographical entities into a grid that strives to preserve some of the original geographical orientation of the entities. It's easiest to describe with examples. See below.

Install

install.packages("geofacet")
# or from github:
# remotes::install_github("hafen/geofacet")

Example

See here for the package vignette.

Barchart of state rankings in various categories:

library(ggplot2)

ggplot(state_ranks, aes(variable, rank, fill = variable)) +
  geom_col() +
  coord_flip() +
  facet_geo(~ state) +
  theme_bw()

Unemployment rate time series for each state:

ggplot(state_unemp, aes(year, rate)) +
  geom_line() +
  facet_geo(~ state, grid = "us_state_grid2") +
  scale_x_continuous(labels = function(x) paste0("'", substr(x, 3, 4))) +
  ylab("Unemployment Rate (%)")

GDP per capita in relation to EU index (100) for each country in the European Union:

ggplot(eu_gdp, aes(year, gdp_pc)) +
  geom_line(color = "steelblue") +
  facet_geo(~ name, grid = "eu_grid1", scales = "free_y") +
  scale_x_continuous(labels = function(x) paste0("'", substr(x, 3, 4))) +
  ylab("GDP Per Capita in Relation to EU Index (100)") +
  theme_bw()

Copy Link

Version

Install

install.packages('geofacet')

Monthly Downloads

1,128

Version

0.2.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

November 30th, 2023

Functions in geofacet (0.2.1)

grid_preview

Plot a preview of a grid
get_ne_data

Get rnaturalearth data
grid_design

Interactively design a grid
india_pop

india_pop
plot.facet_geo

Plot geofaceted ggplot2 object
grid_auto

Generate a grid automatically from a country/continent name or a SpatialPolygonsDataFrame or `sf` polygons
grid_submit

Submit a grid to be included in the package
print.facet_geo

Print geofaceted ggplot2 object
london_afford

london_afford
state_unemp

state_unemp
nhs_scot_dental

nhs_scot_dental
state_ranks

state_ranks
grids

Geo Grids
sa_pop_dens

sa_pop_dens
facet_geo

Arrange a sequence of geographical panels into a grid that preserves some geographical orientation
get_grid_names

Get a list of valid grid names
attach_spdf

Attach a SpatialPolygonsDataFrame object to a grid
eu_imm

eu_imm
get_geofacet_grob

Perform post-processing on a facet_geo ggplot object
geofacet

geofacet
eu_gdp

eu_gdp
aus_pop

aus_pop
auto_states

auto_states
election

election