Pacific-centric Robinson projection with ggplot in R
Asked Answered
P

1

2

I'm trying to create a pacific-centric Robinson projection in R with ggplot...

converting a shapefile to a Robinson CRS using spTransform and setting longitude to 150 degrees doesn't work, and fortify errors out.

like this:

world_robin <- spTransform(world2, CRS("+proj=robin +lon_0=150 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"))
plot(world_robin, col = "khaki", bg = "azure2")

And there doesn't appear to be a way to do it later in the process when setting a projection for ggmap: ie,

coord_map("mollweide", orientation=c(90, 0, 150)) 

this appears to be the best, but it's not quite there.

Pancake answered 15/9, 2015 at 16:42 Comment(3)
p.s. I'm using a 1:110m shapefile from Natural Earth.Pancake
You can edit the question instead of adding it to the comments.Humbertohumble
Anyone with this same question, I recommend checking out this related answer using the latest sfMensal
P
4

You'll need GDAL / rgdal for this and it's 180 vs 150 but you should be able to extrapolate. GIS SO FTW!

library(ggplot2)
library(ggthemes)
library(sp)
library(rgdal)

# assumes you are in the ne_110m... directory
# split the world and stitch it back together again

system("ogr2ogr world_part1.shp ne_110m_admin_0_countries.shp -clipsrc -180 -90 0 90")
system("ogr2ogr world_part2.shp ne_110m_admin_0_countries.shp -clipsrc 0 -90 180 90")
system('ogr2ogr world_part1_shifted.shp world_part1.shp -dialect sqlite -sql "SELECT ShiftCoords(geometry,360,0), admin FROM world_part1"')
system("ogr2ogr world_0_360_raw.shp world_part2.shp")
system("ogr2ogr -update -append world_0_360_raw.shp world_part1_shifted.shp -nln world_0_360_raw")

world <- readOGR("ne_110m_admin_0_countries/world_0_360_raw.shp", "world_0_360_raw")
world_robin <- spTransform(world, CRS("+proj=robin +lon_0=180 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"))

world_dat <- fortify(world_robin)

gg <- ggplot()
gg <- gg + geom_map(data=world_dat, map=world_dat,
                    aes(x=long, y=lat, map_id=id),
                    fill="khaki", color="black", size=0.25)
gg <- gg + coord_equal()
gg <- gg + theme_map()
gg <- gg + theme(plot.background=element_rect(fill="azure2"))
gg

enter image description here

You can use gdalUtils for this as well, but it just calls the system binaries and you have to specify the clipping polygons with well known strings (so the system call is a few characters shorter for the line).

FYI: Doing this means you have to shift and project all points/shapes before plotting with ggplot2.

Purpleness answered 15/9, 2015 at 19:59 Comment(1)
Excellent. Thanks very much.Pancake

© 2022 - 2024 — McMap. All rights reserved.