3

I'm using R 3.1.2, trying to create a choropleth using a world map. The quirk is that, because my audience is in Asia I need to recenter the map. From the documentation it seems like nowrapRecenter() is perfect for this, but I find that it doesn't seem to work as advertised. For example, start without any recentering:

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

Now try to recenter at 148E longitude, in order to move Asia closer to the centre of the map while splitting as few land masses as possible at the left/right margins:

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

What you get is a bit messy. Not only is the map centred at 180E longitude, but there are scratches all across the map where polygons which nowrapRecenter() should have been divided and re-closed at the left/right are extending across the full width of the map. In fact recentering does not appear to work cleanly for any chosen offset.

A similar question came up before, and the final comment there provided an example using nowrapRecenter(), but it no longer seems to work. What's the best way to recenter a world map (using SpatialPolygons) and have the polygons at the left/right margins be properly divided?

Thanks!

Community
  • 1
  • 1
user4294565
  • 131
  • 5
  • When I ran your code up to plot(world), Error in recenter(nowrapSpatialPolygons(obj, offset = offset, eps = eps, : error in evaluating the argument 'obj' in selecting a method for function 'recenter': Error in loadNamespace(name) : there is no package called ‘gpclib’ – lawyeR Dec 26 '14 at 12:59
  • Ah, you probably need to have the sp and rgeos (or gpclib, but beware license issues) libraries installed in your R environment. If they're there, they should be loaded automatically. Sorry about that! – user4294565 Dec 28 '14 at 07:02

1 Answers1

0

This is only a partial answer, so if it's not adequate let me know and I'll delete it.

The problem appears to be that transforming a Mercator projection fails near the poles. If you are willing 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 restriction, nowrapRecenter(...) failed.

jlhoward
  • 58,004
  • 7
  • 97
  • 140
  • It's curious isn't it, since this is exactly the sort of problem that nowrapRecenter() seems to have been designed to deal with. I wonder if something has changed behind the scenes so that the function now longer works? Thanks very much for the alternative way of doing it! Unfortunately in this particular case Antarctica and Greenland are both significant to the data. But please don't delete your answer. It's very useful to know about! – user4294565 Dec 28 '14 at 06:57