Map Details in R

75 Views Asked by At

I have a two-part question:

  1. I am struggling to figure out how to make the Northeast United States' abbreviations on my map smaller so they actually fit in the state boundaries, or if I could make those lines that point to the state. My apologies, I have little background in cartography.

Specifically, VA, MT, CT, NJ are all small states, and that part of the map looks crowded.

  1. I would like to put some kind of text outline to see the text against the white background. Is there code for that?

Here is my current code:

# apply state abbreviations
centroid_labels <- usmapdata::centroid_labels("states") # df with lat and long coordinates, state anme, and abbreviations
state_labels <- merge(statecounts, centroid_labels, by = "fips") # merge above df


myPalette <- colorRampPalette(rev(brewer.pal(11, "RdYlBu")))

usmap3 <- plot_usmap(data = statecounts, regions = "state", values = "n") +
  geom_text(data = state_labels, aes(x = x, y = y, label = stateabbr), color = "white") +
  scale_fill_gradientn(name = "Count", colours = myPalette(50)) +
  labs(title = "Frequency of Unique Users in the United States",
       caption = "",
       fill = "Count")
usmap3

And here is my map:

US Map heat map showing location frequency of users who responded to a survey

1

There are 1 best solutions below

0
René On

geom_text has a size attribute that you can set. In your case try:

usmap3 <- plot_usmap(data = statecounts, regions = "state", values = "n") +
  geom_text(
    data = state_labels, 
        aes(
            x = x, 
            y = y, 
            label = stateabbr), 
    color = "white",
    size = 1)