Correct use of nowrapRecenter ()

I am using R 3.1.2 trying to create choropleth using world map. The quirk is that since my audience is in Asia, I need to return the card. From the documentation it seems that nowrapRecenter () is perfect for this, but I believe it doesn't work as advertised. For example, start without any retyping:

library(maps)
library(maptools)
library(rgdal)
data(wrld_simpl)
plot(wrld_simpl)

      

Now try going back to 148E longitude to move Asia closer to the center of the map, splitting as little land as possible from the left / right fields:

library(maps)
library(maptools)
library(rgdal)
data(wrld_simpl)
world <- nowrapRecenter(wrld_simpl,offset=148,avoidGEOS=TRUE)
plot(world)

      

What you get is a little messy. Not only is the map centered at 180 ° longitude, but there are scratches all over the map, where the polygons that nowrapRecenter () should have been split and closed again on the left / right are spread across the entire width of the map. In fact, reclosing doesn't work with purity for any selected offset.

A similar question came up before , and the last comment gave an example of using nowrapRecenter (), but it doesn't work anymore. What is the best way to reposition the world map (using SpatialPolygons) and properly divide polygons into left / right margins?

Thank!

+3


source to share


1 answer


This is only a partial answer, so if it doesn't match me, let me know and I'll remove it.

The problem is that the Mercator projection transform fails near the poles. If you want to exclude Greenland and Antarctica, this works.



library(maptools)
data(wrld_simpl)
wrld   <- wrld_simpl[!(wrld_simpl$NAME %in% c("Greenland","Antarctica")),]
library(ggplot2)
ggplot(wrld,aes(x=long,y=lat,group=group))+
  geom_polygon(fill="white",color="grey30")+
  coord_map(orientation=c(90,0,148))+
  scale_x_continuous(breaks=c(0,60,120,180,-120,-60))+
  theme_bw()

      

Even with this limitation nowrapRecenter(...)

it failed.

0


source







All Articles