2

Currently, I have this

library(usmap)
library(ggplot2)
plot_usmap(states = "states") + 
  labs(title = "US States",
  subtitle = "This is a blank map of the counties of the United States.") + 
  theme(panel.background = element_rect(color = "BLACK", fill = "GRAY"))

how would I make certain states like Texas, Utah, and Oklahoma one color, and other states like California, Maine, and Oregon another color.

Axeman
  • 32,068
  • 8
  • 81
  • 94
Anna Alves
  • 21
  • 2
  • I think your code should have `plot_usmap(regions = "states")`, not `plot_usmap(states = "states")`, correct? – Axeman Nov 19 '21 at 02:04

1 Answers1

3

I think you need to write the plotting yourself in that case, but luckily that isn't too difficult. Here's an example:

# choose your states
my_states <- c('Texas', 'Utah', 'Oklahoma')
# get the data
d <- us_map(regions = "states")

# now plot manually. The `full` here refers to the full name of the state, 
# which is a column in `d`. Use `abbr` to use abbreviations.
ggplot(d, aes(x, y, group = group, fill = full %in% my_states)) +
  geom_polygon(color = 'black') +
  coord_equal() +
  # Choose your two colors here:
  scale_fill_manual(values = c('white', 'firebrick'), guide = 'none') +
  usmap:::theme_map() +
  labs(
    title = "US States",
    subtitle = "This is a blank map of the counties of the United States."
  ) + 
  theme(panel.background = element_rect(color = "BLACK", fill = "GRAY"))

enter image description here

Axeman
  • 32,068
  • 8
  • 81
  • 94