从ggplot2地图中删除国家的政治边界

问题描述 投票:0回答:1

我需要从以下ggplot2地图中删除这些国家的政治边界:

library(ggplot2)

world = map_data('world')

plot=ggplot() +
geom_polygon(data=world, aes(x=long, y=lat, group=group), fill='NA', color='black', size=0.2)

print(plot)

enter image description here

关于如何执行此操作的任何建议?谢谢

ggplot2 country borderless world-map
1个回答
1
投票

您的问题有两种解决方法:

第一个解决方法:使用地图代替ggplot2

library(maps)    
world <- maps::map("world", fill=FALSE, plot=TRUE, interior = FALSE)

将导致:

enter image description here

第二种解决方法:使用地图和ggplot2

library(maps)
library(magrittr)
library(maptools)
library(raster)
library(ggplot2)

#Defining a general CRS
mycrs <- "+proj=longlat +datum=WGS84 +no_defs"

#Using the original maps package, then converting map into SpatialPolygons object
world <- maps::map("world", fill=TRUE) %$% 
  maptools::map2SpatialPolygons(., IDs=names,proj4string=CRS(mycrs))

#The resulting map has self intersection problems so any further operation reports errors; using buffers of width 0 is a fast fix
while(rgeos::gIsValid(world)==FALSE){
  world <- rgeos::gBuffer(world, byid = TRUE, width = 0, quadsegs = 5, capStyle = "ROUND")
}

#Dissolving polygon's limits
world <- raster::aggregate(world)

#Plotting. I add theme_void to your code to erase any axis, etc
ggplot() +
  geom_polygon(data = world, aes(x=long, y=lat, group=group), fill='NA', color='black', size=0.2)+
  theme_void()

结果:

enter image description here

希望有帮助

© www.soinside.com 2019 - 2024. All rights reserved.