I would like to map data by US census regions. In short, I have state-level data, which I joined to latitude/longitude coordinates using the maps package. Here are the first 20 lines of the resulting dataframe:
df_F4 %>% select(state, division, percap_rheum, group, long, lat) %>% print(n=20)
# A tibble: 15,539 x 6
# Groups: division [9]
state division percap_rheum group long lat
<chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 alabama east south central 70255. 1 -87.5 30.4
2 alabama east south central 70255. 1 -87.5 30.4
3 alabama east south central 70255. 1 -87.5 30.4
4 alabama east south central 70255. 1 -87.5 30.3
5 alabama east south central 70255. 1 -87.6 30.3
6 alabama east south central 70255. 1 -87.6 30.3
7 alabama east south central 70255. 1 -87.6 30.3
8 alabama east south central 70255. 1 -87.6 30.3
9 alabama east south central 70255. 1 -87.7 30.3
10 alabama east south central 70255. 1 -87.8 30.3
11 alabama east south central 70255. 1 -87.9 30.2
12 alabama east south central 70255. 1 -87.9 30.2
13 alabama east south central 70255. 1 -88.0 30.2
14 alabama east south central 70255. 1 -88.0 30.2
15 alabama east south central 70255. 1 -88.0 30.3
16 alabama east south central 70255. 1 -88.0 30.3
17 alabama east south central 70255. 1 -88.0 30.3
18 alabama east south central 70255. 1 -88.0 30.3
19 alabama east south central 70255. 1 -87.9 30.3
20 alabama east south central 70255. 1 -87.8 30.3
# … with 15,519 more rows
I want to graph it with ggplot2, organized by census regions. I have aggregated the data by regions and can graph it at a state level as such:
graph_theme <- theme_light() +
theme(
text = element_text(size=10),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
plot.margin = unit(c(0.75, 0.25, 0.5, 0.5), "cm")) #top, R, bottom, L)
map_theme <- theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank(),
legend.title = element_blank(),
legend.position = c(0.92, 0.25), # h / v
legend.background = element_blank()
)
df_F4 %>%
ggplot(aes(
long,
lat,
group = group)) +
geom_polygon(aes(fill = percap_rheum), color = "white") +
scale_fill_viridis_c(labels = dollar_format(big.mark = ","), direction = -1) +
graph_theme +
map_theme
Which results in this picture:
You can tell that there are census divisions there, but I want to highlight them or outline them somehow. Any advice would be greatly appreciated!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…