remove Antarctica from wrld_simpl global map

守給你的承諾、 提交于 2019-12-23 20:11:42

问题


I use wrld_simpl as a background in my ggplots and would like to remove Antarctica. Not sure how to do it though. Thank you for your help!

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

Example of script:

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

回答1:


I haven't used that package in particular, but ggplot2::map_data() calls maps from the maps package. Then you can subset it using dplyr::filter like any dataframe.

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

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




回答2:


Here is a solution to remove Antarctica (with corresponding UN code = 10)

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

Example of script:

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


来源:https://stackoverflow.com/questions/45801462/remove-antarctica-from-wrld-simpl-global-map

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!