本文介绍了从wrld_simpl全球地图上删除南极洲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在ggplots中使用wrld_simpl作为背景,并希望删除南极洲.虽然不知道如何去做.感谢您的帮助!
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"]
脚本示例:
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
推荐答案
我没有特别使用该软件包,但是 ggplot2 :: map_data()
从 maps
包.然后,您可以像其他数据框一样使用 dplyr :: filter
对其进行子集化.
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()
这篇关于从wrld_simpl全球地图上删除南极洲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!