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:
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
).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.
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.
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.
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.
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))
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))
UPDATED
Here I put some explanations:
The whole data looks like:
ggplot(aes(x = long, y = lat, group = group), data = mp) + geom_path()
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With