我在我的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
答案 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()
答案 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