从wrld_simpl全局地图中删除Antarctica

时间:2017-08-21 16:02:52

标签: r ggplot2 raster

我在我的ggplots中使用wrld_simpl作为背景,并希望删除Antarctica。不知道如何做到这一点。谢谢您的帮助!

library(maptools)
data("wrld_simpl")
plot(wrld_simpl)
wrld_simpl[wrld_simpl@data$ISO3 != "ATA"]

脚本示例:

library(ggplot2)

p <- ggplot() +
  geom_polygon(data = wrld_simpl, aes(x = long, y = lat, group = group), colour = "black", fill = "grey") 
p <- p + geom_raster(data = df , aes(x = x, y = y, fill = layer))
p <- p + coord_equal() +  theme_bw()  + labs(x="", y="") 
p <- p + scale_fill_gradientn(colours = rev(terrain.colors(10)))
p <- p + labs(list(title = ""))  
p

2 个答案:

答案 0 :(得分:6)

我没有特别使用该软件包,但ggplot2::map_data()调用maps软件包中的地图。然后,您可以使用dplyr::filter像任何数据帧一样对其进行子集化。

library(dplyr)
library(maps)
library(ggplot2)

map_data("world") %>% 
  filter(region != "Antarctica") %>% 
  ggplot(aes(long, lat, group = paste(region, group))) + 
  geom_polygon() + 
  coord_fixed()

enter image description here enter image description here

答案 1 :(得分:2)

以下是移除南极洲的解决方案(相应的UN代码= 10)

wrld_simpl[wrld_simpl@data$UN!="10",]

脚本示例:

p <- ggplot() +
  geom_polygon(data = wrld_simpl[wrld_simpl@data$UN!="10",], aes(x = long, y = lat, group = group), colour = "black", fill = "grey") 
p <- p + geom_raster(data = df , aes(x = x, y = y, fill = layer))
p <- p + coord_equal() +  theme_bw()  + labs(x="", y="") 
p <- p + scale_fill_gradientn(colours = rev(terrain.colors(10)))
p <- p + labs(list(title = ""))  
p