使用geom_sf()绘制sf对象,并使用除lat-long之外的任何投影

时间:2017-07-03 14:06:12

标签: r ggplot2 axes map-projections sf

我试图在lat-long以外的任何投影中用geom_sf()绘制多边形。

我正在使用manual pages for geom_sf()中的示例 导入数据集:

nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)

从latlong转换为epsg:3857

nc_3857 <- sf::st_transform(nc, "+init=epsg:3857")

最后使用ggplot2绘制,用于定义绘图的crs:

ggplot() +
 geom_sf(data = nc_3857, colour = "red", fill = NA) +
 coord_sf(crs=st_crs(3857))

我一直在wgs84(即epsg:4326)中获得一张带有长轴的地图。我想让轴以米为单位,所以我需要ggplot来绘制投影多边形。我做错了什么?

提前致谢 泽

2 个答案:

答案 0 :(得分:5)

另请参阅https://github.com/tidyverse/ggplot2/issues/2200并尝试

ggplot() +  geom_sf(data = nc_3857, colour = "red", fill = NA) +
   coord_sf(datum=st_crs(3857))

给出了

enter image description here

答案 1 :(得分:1)

它正在所请求的投影中绘制它,它只是覆盖了一个长期的刻度。

如果您尝试与挪威类似的东西,例如,靠近北极,您可以看到显示X-Y坐标是转换的坐标,但是重叠的刻度是纬度。这是挪威的地图,位于epsg 3035(圆锥形)坐标:

enter image description here

因此 绘制投影多边形。如果此处的纬线较长的线条是网格,那么它将在拉长投影中绘制坐标。

文档中唯一提到的刻度是coord_sf

datum: CRS that provides datum to use when generating graticules

并没有多说。

你只想要一个笛卡尔坐标系?哦,试试吧:

> ggplot() +  geom_sf(data = rp, colour = "red", fill = NA) + coord_cartesian()
Error: geom_sf() must be used with coord_sf()

使用geom_sf检查ggplot2问题以获取备用刻度,如果没有任何内容则添加问题。