R语言世界地图转为SpatialPolygons以及去除地图内国家边界
作者:互联网
##加载包
library(maps)
library(maptools)
library(ggplot2)
library(metR)
##提取地图并转换为Spatialpolygons
loc <- maps::map('world',interior = FALSE,
plot = FALSE, fill = TRUE,col = 'transparent')
ids <- sapply(strsplit(loc$names, ":"), function(x) x[1])
loc <- map2SpatialPolygons(map = loc, IDs = ids,proj4string = CRS('+proj=longlat +datum=WGS84 +no_defs'))
##去除内边界
worldmap1 <- unionSpatialPolygons(loc, IDs = rep(1,length(loc)))
##画图
worldmap2 <- fortify(worldmap1)
ggplot()+
scale_x_longitude(expand = c(0, 0), breaks = seq(-180, 180, 45))+
scale_y_latitude(expand = c(0, 0), breaks = seq(-90, 90, 30))+
geom_polygon(data = worldmap2,
mapping = aes(x = long, y = lat, group = group),
colour = 'gray', fill = 'gray', size = 0.5)
##结果图
标签:边界,##,SpatialPolygons,地图,library,worldmap2,世界地图,去除 来源: https://blog.csdn.net/hao_liangliang/article/details/112320624