【问题标题】:Pacific-centric Robinson projection with ggplot in R在 R 中使用 ggplot 进行以太平洋为中心的 Robinson 投影
【发布时间】:2015-12-12 00:33:05
【问题描述】:

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

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

像这样:

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 设置投影时,似乎没有办法在该过程的后期执行此操作: 即,

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

这似乎是最好的,但它并不完全在那里。

【问题讨论】:

  • 附注我使用的是 Natural Earth 的 1:110m shapefile。
  • 您可以编辑问题而不是将其添加到 cmets。

标签: r dictionary ggplot2 map-projections


【解决方案1】:

为此,您需要 GDAL / rgdal,它是 180 与 150,但您应该能够推断。 GIS 太棒了!

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 调用对于该行来说要短几个字符)。

仅供参考:这样做意味着您必须在使用 ggplot2 绘图之前移动和投影 所有 个点/形状。

【讨论】:

  • 优秀。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2013-02-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多