我正在尝试构建一个州地图,其中各县已轮廓化,并且其中一个县被涂成蓝色,同时标出一个特定度假村的位置。不幸的是,我无法将县染色或添加特定点。我的代码基于http://eriqande.github.io/rep-res-web/lectures/making-maps-with-R.html。感谢您的任何见解!
library(ggplot2)
library(ggmap)
library(maps)
library(mapdata)
states <- map_data("state")
dim(states)
ut_df <- subset(states, region == "utah")
head(ut_df)
counties <- map_data("county")
ut_county <- subset(counties, region == "utah")
head(ut_county)
ut_base <- ggplot(data = ut_df, mapping = aes(x = long, y = lat, group =
group)) +
coord_fixed(1.3) +
geom_polygon(color = "black", fill = "gray")
ut_base + theme_nothing() +
geom_polygon(data = ut_county, fill = NA, color = "white") +
geom_polygon(color = "black", fill = NA) # get the state border back on top