I've picked up a project that requires me to plot custom regions within the United States (including OCONUS regions and territories). Because the whole data set is huge, I've put a "small" subset
Eventually I would like to add other collections of counties, but before I can do that, I need to figure this out. I'm sure this is a fundamental something when creating maps like this, but I've not done this before. Any suggestions?
CodePudding user response:
Your csv contains a plotting order, and the polygons are only drawn correctly if you order the data according to this order. For the subset you provided, we can do:
library(ggplot2)
url <- paste0("https://raw.githubusercontent.com/",
"Doc-Midnight/Test_Dir/main/AZExample.csv")
allgeo <- read.csv(url)
ggplot()
geom_polygon(data = allgeo[order(allgeo$order),],
aes(x = long, y = lat, group = group, fill = sregion),
color = "black")
coord_map(xlim = c(-115, -108), ylim = c(30, 37.5))
theme_void()
Created on 2022-04-14 by the reprex package (v2.0.1)