问题
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