I am overlaying a world map from the maps package onto a ggplot2 raster geometry. However, this raster is not centered on the prime meridian (0 deg), but on 180 deg (roughly the Bering Sea and the Pacific). The following code gets the map and recenters the map on 180 degree:
require(maps)
world_map = data.frame(map(plot=FALSE)[c("x","y")])
names(world_map) = c("lon","lat")
world_map = within(world_map, {
lon = ifelse(lon < 0, lon + 360, lon)
})
ggplot(aes(x = lon, y = lat), data = world_map) + geom_path()
which yields the following output:

Quite obviously there are the lines draw between polygons that are on one end or the other of the prime meridian. My current solution is to replace points close to the prime meridian by NA, replacing the within call above by:
world_map = within(world_map, {
lon = ifelse(lon < 0, lon + 360, lon)
lon = ifelse((lon < 1) | (lon > 359), NA, lon)
})
ggplot(aes(x = lon, y = lat), data = world_map) + geom_path()
Which leads to the correct image. I now have a number of question:
- There must be a better way of centering the map on another meridian. I tried using the
orientationparameter inmap, but setting this toorientation = c(0,180,0)did not yield the correct result, in fact it did not change anything to the result object (all.equalyieldedTRUE). - Getting rid of the horizontal stripes should be possible without deleting some of the polygons. It might be that solving point 1. also solves this point.
Here’s a different approach. It works by:
mapspackage into aSpatialLinesobject with a geographical (lat-long) CRS.SpatialLinesmap into the Plate Carée (aka Equidistant Cylindrical) projection centered on the Prime Meridian. (This projection is very similar to a geographical mapping).rgeospackage.)lon_0in terminology taken from thePROJ_4program used byspTransform()in thergdalpackage).rgeospackage.)This is obviously a lot of work, but leaves one with maps that are minimally truncated, and can be easily reprojected using
spTransform(). To overlay these on top of raster images withbaseorlatticegraphics, I first reproject the rasters, also usingspTransform(). If you need them, grid lines and labels can likewise be projected to match theSpatialLinesmap.