我试图从 shp 文件中绘制俄罗斯,但俄罗斯总是分为两部分。我怎样才能让俄罗斯一气呵成?
我尝试了几个 shp 文件,例如 http://www.naturalearthdata.com/downloads/10m-culture-vectors/ Admin 1 – States, Provinces ;下载无大湖 (14.11 MB) 3.0.0 版
shp <- readOGR("ne_10m_admin_1_states_provinces_lakes.shp")
Run Code Online (Sandbox Code Playgroud)
子集到俄罗斯
names(shp)
rus <- shp[shp$admin == "Russia" , ]
x11()
plot(rus)
Run Code Online (Sandbox Code Playgroud)
由于要绘制它,因此可以将 shapefile 强化到数据框,修改 -180 区域中的经度坐标,并将结果绘制在ggplot:
library(rgdal); library(ggplot2)
# read in the shapefile & subset to Russia
shp <- readOGR(dsn = "ne_10m", layer = "ne_10m_admin_1_states_provinces_lakes")
rus <- shp[shp$admin == "Russia", ]
# fortify to data frame & modify longitude coordinates in the -180 region.
rus.fortify <- fortify(rus) %>%
mutate(long = ifelse(long < -100, long + 180*2, long))
# plot to verify
ggplot(rus.fortify,
aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "white", col = "black") +
coord_map() #default projection is mercator
Run Code Online (Sandbox Code Playgroud)
我还刚刚从这篇文章中了解到,您可以指定不同的投影系统。鉴于俄罗斯有多大,这应该是相关的:
ggplot(rus.fortify,
aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "white", col = "black") +
coord_map("azequalarea")
Run Code Online (Sandbox Code Playgroud)