Hey there,
I am trying to create a map with two county-level variables and state-level boundaries, something like this:
Here is an example of the code I am working on current code, it depicts county US population (continuous, purple/green gradient) and counties w/ + 1 million population (white and black stripes):
library("tidyverse")
library("usmap")
county_pop_info <- usmap::countypop %>%
mutate(pop_2015_millions = pop_2015/100000,
pop_2015_over_million = ifelse(pop_2015_millions > 1, ">= 1 million", "< 1 million"))
#County population size
usmap::plot_usmap(regions = "counties",
data = county_pop_info,
values = "pop_2015_millions",
linewidth = 0) +
scale_fill_continuous(type = "viridis",
name = "Population") +
theme(legend.position = "right") +
#Counties that are over 1 million
geom_polygon_pattern(
data = usmapdata::us_map(regions = "counties") %>%
dplyr::right_join(county_pop_info, by = "fips") %>%
dplyr::filter(pop_2015_over_million == ">= 1 million"),
aes(x, y, group = group),
color = NA,
linewidth = 0.2,
fill = 'white',
pattern_spacing = 0.15,
pattern_density = 0.4,
pattern_fill = 'black') +
#Plot state level borders: How to https://stackoverflow.com/questions/72543606/how-to-make-census-region-border-thicker-on-usmap-packake-r
geom_polygon(data = usmapdata::us_map(regions = "states"),
aes(x, y, group = group), fill = NA, linewidth = 0.5, color = "red")
My issue is that I want the stripes for counties with +1 million population to each be striped (versus stripes across all counties).
An earlier post serves as a great example of this issue, but I wasn't able able to do so with geom_map_pattern
: ggplot2 pattern fill polygons by variable