[英]Making a state map highlighting a specific county and point in R (ggmaps, maps, ggplot2)
我正在嘗試繪制一張州地圖,上面勾勒出各縣的輪廓,並用藍色標出一個縣,其中有一個特定度假勝地。 las,我在給縣上色或添加特定點時遇到麻煩。 我的代碼基於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
# Select a subregion
single_county <- subset(ut_county, subregion=="utah")
# Fill the selected subregion with a predefined color and
# plot a colored point with a specified long. and lat.
ut_base + theme_void() +
geom_polygon(data = ut_county, fill = NA, color = "white") +
geom_polygon(color = "black", fill = NA) +
geom_polygon(data = single_county, fill = "red", color = "white") +
geom_point(x=-111.8, y=40.2, col="blue", size=3)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.