Using usmap
, I have made a plot of values by US counties from some values stored in a variable county
. Before I recently updated R and all my packages, I could easily create a county map with thick state borders and with state abbreviations using the following code:
library(ggplot2)
library(usmap)
centroid_labels = usmapdata::centroid_labels("states")
plotdf = data.frame(cbind(county$FIPS,county$SES)); plotdf[,2] = as.numeric(as.character(plotdf[,2])); names(plotdf) = c("fips", "SES");
plot_usmap(data = plotdf, values = "SES", color = NA) + # color = NA removes county boundary lines
geom_polygon(data = usmapdata::us_map(regions = "states"), aes(x, y, group = group), fill = NA, linewidth = 1, color = "black") + # Keep state boundary lines
geom_text(data = centroid_labels, aes(x = x, y = y, label = abbr), fontface = "bold", colour = "gray12", size = 3)
With a few more lines to change colors and such, that would produce a picture like this:
However, as mentioned, since I updated packages, this doesn’t work for me anymore. Specifically, it gives me and error that the object x
wasn’t found. Searching for an answer, it seems like others have stumbled into a similar issue. This means that I can draw the counties, but the code lines that creates state lines and state abbreviations no longer work. Removing what doesn’t work, it will produce something like this:
Question: Is there any other way to draw state boundaries in this county map and also add state abbreviations?