1

目前,我有这个

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"))

我如何让德克萨斯、犹他和俄克拉荷马等某些州成为一种颜色,而加利福尼亚、缅因州和俄勒冈等其他州则成为另一种颜色。

4

1 回答 1

2

我认为在这种情况下您需要自己编写绘图,但幸运的是这并不太难。这是一个例子:

# 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"))

在此处输入图像描述

于 2021-11-19T02:17:18.413 回答