I am trying to plot Russia from a shp-file, but Russia always comes up as in two parts. How do I get Russia back together in one piece?
I have tried several shp-files e.g. http://www.naturalearthdata.com/downloads/10m-cultural-vectors/ Admin 1 – States, Provinces ; Download without large lakes (14.11 MB) version 3.0.0
shp <- readOGR("ne_10m_admin_1_states_provinces_lakes.shp")
Subset to Russia
names(shp)
rus <- shp[shp$admin == "Russia" , ]
x11()
plot(rus)
Since you want to plot it, you can fortify the shapefile to data frame, modify the longitude coordinates in the -180 region, & plot the result in 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
I've also just learned from this post that you can specify different projection systems. Given how large Russia is, this ought to be relevant:
ggplot(rus.fortify,
aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "white", col = "black") +
coord_map("azequalarea")