Is there a way to plot the two counties side by side (without changing actual scale) to compare their sizes.
I wish to plot San Diego and Santa Clara side by side to demonstrate their actual size.
Thanks
library(tigris)
library(ggplot2)
san_diego <- county_subdivisions(state = "CA", county = "San Diego County", cb = TRUE, year = NULL)
santa_clara <- county_subdivisions(state = "CA", county = "Santa Clara County", cb = TRUE, year = NULL)
gg_san_diego <- ggplot() +
geom_sf(data = san_diego,
color="black",
fill="white",
size=0.25)
gg_santa_clara <- ggplot() +
geom_sf(data = santa_clara,
color="black",
fill="white",
size=0.25)
gg_san_diego
gg_santa_clara
A straightforward way to do this is to move the counties to the same location by subtracting their centroids, then faceting by county name. Here's a fully reproducible example:
library(tigris)
library(tidyverse)
library(sf)
county_subdivisions(state = "CA", cb = TRUE, year = NULL,
county = c("San Diego County", "Santa Clara County")) %>%
group_by(NAMELSADCO) %>%
mutate(geometry = geometry - st_centroid(st_union(geometry))) %>%
ggplot() +
geom_sf(color = "black", fill = "white") +
facet_wrap(.~NAMELSADCO) +
theme_void(base_size = 20) +
theme(strip.text = element_text(margin = margin(20, 20, 20, 20)),
panel.background = element_rect(fill = "gray95", color = NA))