I am working on highlighting groups of counties within Ohio and while I am happy with where I have ended up overall, I have one aesthetic issue I cannot seem to solve.
Goal: Map of Ohio with grouped counties filled white with red outer border around group, and ungrouped counties in gray.
Here's a clip of what the issue looks like on a corner of my full map.

I am trying to get rid of that extra border that is outside of the border of Ohio on groups of counties. The red line inside the groups of counties is great and it doesn't have the outside border problem with the grayed-out counties because I put the "nogroup" filled counties after the others in the code. Based on that, I initially thought it was an order of operations issue in the ggplot2 code, but I tried multiple permutations to no avail.
I'll give a smaller dataset below to replicate the issue, but it's worth noting that I actually have 25 groups of counties and therefore filling the groups with different colors doesn't work because you wouldn't be able to get enough colors that can easily be differentiated (Unless someone has code that allocates colors to polygons based on contrast with adjacent colors? Then you could use a more limited palette and repeat colors across the geographic area...).
# access data
if (!exists(hasRun)) {
OHstate = tigris::states(cb=TRUE, class='sf') |> subset(NAME=='Ohio')
OHcounties = tigris::counties(state='OH', cb=TRUE, class ='sf')
hasRun=TRUE
}
# make groups
group1 = OHcounties |> subset(GEOID %in% c(39055, 39085, 39007))
group2 = OHcounties |> subset(GEOID %in% c(39103, 39153))
nogroup = OHcounties |> subset(GEOID %in% c(39129, 39073, 39141, 39047, 39065,
39091, 39139, 39029, 39151, 39035,
39093, 39033, 39175, 39161, 39075,
39009, 39087, 39001, 39135))
and plot
library(ggplot2)
map <- ggplot() +
geom_sf(data = st_union(group1), color = "#C12637", linewidth = 3, fill = "white") +
geom_sf(data = st_union(group2), color = "#C12637", linewidth = 3, fill = "white") +
geom_sf(data = OHcounties, color = "black", fill = NA) +
geom_sf(data = nogroup) +
geom_sf(data = OHstate, color = "black", linewidth = 1, fill = NA) +
scale_fill_identity() +
theme_void()
map

