Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use different center than the prime meridian in plotting a world map

Tags:

r

ggplot2

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:

enter image description here

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:

  1. There must be a better way of centering the map on another meridian. I tried using the orientation parameter in map, but setting this to orientation = c(0,180,0) did not yield the correct result, in fact it did not change anything to the result object (all.equal yielded TRUE).
  2. 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.
like image 892
Paul Hiemstra Avatar asked May 16 '12 14:05

Paul Hiemstra


People also ask

Where is the prime meridian located on a map?

The prime meridian is the line of 0° longitude, the starting point for measuring distance both east and west around Earth. The prime meridian is arbitrary, meaning it could be chosen to be anywhere. Any line of longitude (a meridian) can serve as the 0° longitude line.

How does the Prime Meridian affect time?

By establishing the prime meridian and zero degrees longitude in Greenwich, the world was then divided into 24 time zones (since the earth takes 24 hours to revolve on its axis) and thus each time zone was established every fifteen degrees of longitude, for a total of 360 degrees in a circle.

How do longitude lines help us navigate time zones?

A day is composed of 24 hours. Thus, it might seem that dividing the earth into 24 time zones would be as simple as dividing 360° by 24 to determine that the time should change by an hour with every 15° of longitude.

What meridian is Hawaii?

Hawai'i is situated between the latitudes of 19° N and 22°N, with its midpoint at 20.5° N.) Stars above south in Honolulu travel in low arcs. The night sky charts below depict the alignment of nine star meridian pointers to South.


1 Answers

This may be somewhat tricky but you can do by:

mp1 <- fortify(map(fill=TRUE, plot=FALSE)) mp2 <- mp1 mp2$long <- mp2$long + 360 mp2$group <- mp2$group + max(mp2$group) + 1 mp <- rbind(mp1, mp2) ggplot(aes(x = long, y = lat, group = group), data = mp) +    geom_path() +    scale_x_continuous(limits = c(0, 360)) 

enter image description here

By this setup you can easily set the center (i.e., limits):

ggplot(aes(x = long, y = lat, group = group), data = mp) +    geom_path() +    scale_x_continuous(limits = c(-100, 260)) 

enter image description here

UPDATED

Here I put some explanations:

The whole data looks like:

ggplot(aes(x = long, y = lat, group = group), data = mp) + geom_path() 

enter image description here

but by scale_x_continuous(limits = c(0, 360)), you can crop a subset of the region from 0 to 360 longitude.

And in geom_path, the data of same group are connected. So if mp2$group <- mp2$group + max(mp2$group) + 1 is absent, it looks like: enter image description here

like image 108
kohske Avatar answered Oct 12 '22 04:10

kohske