2017-08-21 2 views
2

J'utilise wrld_simpl comme arrière-plan dans mes ggplots et je voudrais supprimer l'Antarctique. Je ne sais pas comment le faire quand même. Merci de votre aide!supprimer antarctique de wrld_simpl carte globale

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

Exemple de 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 

Répondre

4

Je n'ai pas utilisé ce paquet en particulier, mais ggplot2::map_data() appelle cartes du paquet maps. Ensuite, vous pouvez le sous-utiliser en utilisant dplyr::filter comme n'importe quelle image.

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

2

Voici une solution pour éliminer l'Antarctique (avec le code correspondant UN = 10)

wrld_simpl[[email protected]$UN!="10",] 

Exemple de script:

p <- ggplot() + 
    geom_polygon(data = wrld_simpl[[email protected]$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