I am attempting to add a layer with state abbreviations to this map:
US Map-- user locations represented by heat plot; no state name abbreviations
I have a list of users from a suvery whose self-reported location I mapped to determine the most popular states. I would like to add a "layer" to this map with state abbreviations.
This is an example of the dataset I'm using. I have a column with the state abbreviations, I just don't know how to layer them on top of the map. Btw I am using library(usmap).
| state | stateabbr | n | fips |
|---|---|---|---|
| Alabama | AL | 1 | 01 |
| Arkansas | AR | 1 | 05 |
| California | CA | 32 | 06 |
| Florida | FL | 19 | 12 |
Lastly, the code for the map:
usmap3 <- plot_usmap(data = statecounts, regions = "state", values = "n") +
scale_fill_gradientn(name = "Count", colours = myPalette(100)) +
labs(title = "Frequency of Unique Users in the United States",
caption = "",
fill = "Count")
usmap3
One simple option would be to use the
labelsargument ofplot_usmapwhich will automatically add labels with state abbreviations for all states.In case that you want only some states to be labelled then you could first get the coordinates of the state centroids which are available via
usmapdata::centroid_labels("states")and join these coordinates to your dataset. Afterwards you could add the state abbreviations to your map viageom_textlike so:DATA