我正在尝试绘制各县的伊利诺伊州底图。 我已加载的库:
library(ggplot2)
library(maps)
library(ggmap)
library(mapdata)
这是我的代码:
states <- map_data("state")
IL <- subset(states, region %in% c("illinois"))
counties <- map_data("county")
IL_county <- subset(counties, region == "illinois")
il_base <- ggplot(data = IL, mapping = aes(x = long, y = lat)) +
coord_fixed(1.3) +
geom_polygon(color = "black", fill = NA) +
theme_nothing()
il_base
il_base +
geom_polygon(data = IL_county, fill = NA, color = "black") +
geom_polygon(color = "black", fill = NA)
il_base
图很好,它显示了状态的基本轮廓。但是,一旦我向其中添加geom_polygon
,就可以像这样映射县:
这不是IL县的样子。我在这里做错了什么?
答案 0 :(得分:1)
我将基本图修改为:
# Add group
il_base <- ggplot(data = IL, mapping = aes(x = long, y = lat, group = group)) +
coord_fixed(1.3) +
geom_polygon(color = "black", fill = NA) +
theme_nothing()