R中具有ggplot的太平洋中心罗宾逊投影 [英] Pacific-centric Robinson projection with ggplot in R

查看:218
本文介绍了R中具有ggplot的太平洋中心罗宾逊投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ggplot在R中创建一个以太平洋为中心的Robinson投影...

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

使用spTransform将shapefile转换为Robinson CRS并将经度设置为150度不起作用,并且fortify出错.

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

像这样:

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")

在为ggmap设置投影时,似乎没有一种方法可以在以后的过程中完成: 即

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.

推荐答案

为此,您将需要GDAL/rgdal,它是180对150,但您应该可以推断. GIS这样FTW!

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

您也可以使用gdalUtils,但是它只是调用系统二进制文件,并且必须使用众所周知的字符串指定剪切多边形(因此system调用比该行短几个字符).

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).

仅供参考:这样做意味着您必须先移位并投影所有个点/形状,然后才能使用ggplot2进行绘制.

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

这篇关于R中具有ggplot的太平洋中心罗宾逊投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆