【发布时间】:2018-02-03 16:27:21
【问题描述】:
我正在使用 ggplot 创建一个地图,并根据我的数据使用渐变填充不同的区域。
默认情况下没有绘制边界线的地图。我想包括它们,并根据this question编写了一些代码。然而,我认为这导致了太多的线,连接了地区的所有角落。我该如何避免这种情况?
在下面的代码中,datafile 是我想要在地图上显示的数据的存储位置,Scot 是 shapefile。
导致问题的线是 geom_polygon。
ggplot() +
geom_map(data = datafile, aes(map_id = region, fill = datafile$"2007"), map = Scot) +
geom_polygon(data = Scot, aes(x = Scot$long, y = Scot$lat), colour = "gray", fill = NA) +
expand_limits(x = Scot$long, y=Scot$lat) +
scale_fill_gradient(low = ("lightyellow"), high = ("red"), limits = c(0,35000)) +
ggtitle("2007") +
coord_fixed(1.2) +
theme(axis.text.x = element_blank(), axis.text.y = element_blank(),
axis.ticks = element_blank(), axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.border = element_blank(), panel.background = element_blank(),
legend.title = element_text(face = "bold"),
plot.title = element_text(face = "bold", hjust = 0.5))
【问题讨论】:
-
不要在
aes中使用$ 表示法。这可能是您的问题的原因。对于名为2007的列,用`s 将其包围