我已经通过使用栅格数据包中的getData函数制作了荷兰的地图。 getData函数下载世界任何地方的地理数据。下载的数据为“ SpatialPolygonsDataFrame”类。
我想用浅灰色填充地图的陆地区域,但是当我尝试填充地图的颜色时,陆地和水域区域都用颜色填充。有几处水域与水坝,土地等交界,并且它们也会变色。
这是我创建地图的方式:
library(raster) #requires sp package
library(ggplot2)
#Download shapefile data for The Netherlands
Neth<-getData("GADM", country="NL", level=1)
#Set general theme options for the ggplot
theme_opts<-list(theme(panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
panel.background = element_blank(),
plot.background = element_blank(),
axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
plot.title = element_blank()))
#Plot map of The Netherlands
ggplot() +
geom_polygon(data=Neth, aes(long,lat,group=group), fill="whitesmoke")+
geom_path(data=Neth, aes(long,lat, group=group), color="black",
size=0.3) +
theme(aspect.ratio=1) + theme_opts
这是我的地图的图像,我添加了文本“水”以显示一些水体:
更新:
我仅通过从地图上保留省份的多边形就可以解决问题:
#Only grab provinces
Neth <- Neth[Neth$TYPE_1 == "Province",]
#Plot map of The Netherlands
ggplot() +
geom_polygon(data=Neth, aes(long,lat,group=group), fill="whitesmoke")+
geom_path(data=Neth, aes(long,lat, group=group), color="black",
size=0.3) +
theme(aspect.ratio=1) + theme_opts