【问题标题】:change projection on geom_sf map更改 geom_sf 地图上的投影
【发布时间】:2021-03-13 21:56:12
【问题描述】:

我需要使用 ggplot 和 geom_sf 绘制美国和加拿大东海岸的地图,但我希望通过投影来做到这一点,该投影将使佛罗里达州到新斯科舍省从东到西不那么夸张,例如 Lambert Conformal ,如图 3.3 所示:https://cran.r-project.org/web/packages/oce/vignettes/map_projections.html

如何在 ggplot 中使用 geom_sf 执行此操作?

这是我到目前为止的部分:

library(rnaturalearth)
library(tidyverse)

world <- ne_countries(scale = "small", returnclass = "sf")

world %>%
ggplot()+
  geom_sf(fill = "darkseagreen3") +
  coord_sf(xlim = c(-87, -50), ylim = c(18, 50), expand = FALSE)+
  theme_classic()+
  theme(axis.ticks=element_blank(),
        axis.text=element_blank(),
        panel.background = element_rect(color="transparent", fill = "transparent"),
        plot.background = element_rect(color="transparent", fill = "transparent"))

这几乎是我需要的区域,但我希望它从东到西不要那么宽。谢谢。

【问题讨论】:

    标签: r mapping spatial shapefile rgeo


    【解决方案1】:

    由于您使用的是简单的要素对象,因此您可以轻松更改坐标系,如下所示:

    reprojected_World <- st_transform(world, 'EPSG:3082')
    

    这里,选择的坐标系是 Lambert Conformal。其他投影代码见https://epsg.org/home.html。祝你的项目好运。

    【讨论】:

    • 我尝试了类似的方法,但是当我运行 ``` reprojected_World %>% ggplot()+ geom_sf() ``` 我得到了一个疯狂的结果。地图是正确的形状,但我不知道如何用这个坐标系裁剪它。
    • @Jake L 是的。乍一看,结果非常奇特,但这只是因为投影的工作方式。它不是用于整个地球的投影,因此您需要使用 coord_sf() 调整框架。在不调整框架的情况下进行绘图会产生几乎无法识别为地图的东西。
    • 如果您在边界框的格式正确时选中它。这将使您了解如何设置 x 和 y 限制,但这需要一些试验和错误。这应该让你开始以美国为中心:coord_sf(xlim = c(-4378820, 8378820), ylim = c(0, 12922790))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    • 2016-10-01
    • 2017-02-20
    • 2019-02-24
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多