将数据框中的经度和纬度坐标重新投影为平胸生物地理分布的莫尔韦德投影

问题描述 投票:0回答:1

我正在努力寻找一种方法来重新投影数据框的坐标,以便我可以将它们绘制到不同的投影中。当我这样做时,所有点都会崩溃到 0,0。所以我认为地图本身正在投影到我想要的投影,但数据不在正确的crs中或者没有crs?

数据框全部来自古生物学数据库,我下载了所有古颌动物的出现数据,它包含,属,种,长,纬度,古拉特,古龙,cc。

这是我的数据集的链接:https://github.com/aamirrr-m/palaeognathae/blob/3ed0d951ba5968be67fdc95793ed3c52c8025386/Palaeognathae_Occurance_dataRevised.csv

**到目前为止,我可以使用 mollweide 投影创建地图,无需任何数据点 **

(https://i.stack.imgur.com/lJQA5.png)

没有任何投影它工作正常并输出:

(https://i.stack.imgur.com/jxght.png)

当我尝试添加数据时,返回的结果是:

(https://i.stack.imgur.com/6820D.png)

(不允许我发布图片,因为我的代表数少于 10)

所以我尝试添加 coord_sf 和投影 [使用

coord_sf(crs = "+proj=moll")
] 或类似的东西。这已添加到代码块底部的最终 ggplot 中。

我确实知道必须首先完成某种形式的转变,只是需要一些帮助来了解如何去做。 我的代码如下:

dput(ratites)

library(maps)
library(dplyr)
library(ggplot2)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
#install.packages("ggthemes")
library(ggthemes)
library(mapproj)
library(tidyverse)
library(sp)

#projection of earth for plotting#### 
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
attach(ratites)

#Mollweide projection
world %>%
  st_transform(crs = "+proj=moll") %>%

  ggplot() +
  geom_sf() +
  geom_sf()
  theme_map()
#Preparing the data####
#this cleasn the data using the tidyverse pipe function selecting 
#only the rows and columns you want to use
Ratite_C <- ratites %>%
  select(accepted_name, Longitude, latitude, early_interval, cc) 

    #subsetting the data####
#they have all now been separated by time bin

Cret <- subset(Ratite_C, early_interval == "Cretaceous")
Paleo <- subset(Ratite_C, early_interval == "Paleocene")
Eoc <- subset(Ratite_C, early_interval == "Eocene")
Oligo <- subset(Ratite_C, early_interval == "Oligocene")
Mioc <- subset(Ratite_C, early_interval == "Miocene")
Plio <-  subset(Ratite_C, early_interval == "Pliocene")
#these two have been combined to show recent ratite biogeography 
Pleis.Holo <- subset(Ratite_C, early_interval == "Pleistocene" | early_interval == "Holocene")
#replotting the map data 

    R.Smap <- ggplot() +
  geom_sf(data = world, color = "black", fill = "white", ) +
  geom_point(data = Cret, aes( x = Longitude, y = latitude), size = 3, 
             shape = 23, fill = "orange") +
  geom_point(data = Paleo, aes( x = Longitude, y = latitude), size = 3, 
             shape = 21, fill = "lightblue") +
  geom_point(data = Eoc, aes( x = Longitude, y = latitude), size = 3, 
             shape = 21, fill = "goldenrod4") +
  geom_point(data = Oligo, aes( x = Longitude, y = latitude), size = 3, 
             shape = 21, fill = "yellow") +
  geom_point(data = Mioc, aes( x = Longitude, y = latitude), size = 3, 
             shape = 21, fill = "purple") +
  geom_point(data = Plio, aes( x = Longitude, y = latitude), size = 3, 
             shape = 21, fill = "green") +
  geom_point(data = Pleis.Holo, aes( x = Longitude, y = latitude), size = 2, 
             shape = 21, fill = "cyan") +
theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(), 
    panel.background = element_rect(fill = 'azure2'))`

    R.Smap
r coordinate-systems coordinate-transformation map-projections geom-sf
1个回答
0
投票

在绘制之前,您必须将

rarites
data.frame 转换为 sf 并将其重新投影到 Mollweide,例如:

a <- read.csv("https://raw.githubusercontent.com/aamirrr-m/palaeognathae/3ed0d951ba5968be67fdc95793ed3c52c8025386/Palaeognathae_Occurance_dataRevised.csv")
  
b <- a |>
  sf::st_as_sf(coords = c("Longitude", "latitude"), crs = "EPSG:4326") |>
  sf::st_transform(crs = "+proj=moll")

data(World, package = "tmap")

w <- World |>
  subset(select = name) |>
  sf::st_transform(crs = "+proj=moll")

tmap::tm_shape(w) +
  tmap::tm_polygons() +
  tmap::tm_shape(b) +
  tmap::tm_dots()

创建于 2024-01-04,使用 reprex v2.0.2

coord_sf(crs = "+proj=moll")
设置对象的 crs,但不会重新投影它。
st_transform()
是正确的功能。在上面的示例中,我使用
{tmap}
包来绘制地图而不是 ggplot。

图像中 0,0 坐标周围的点的集合:

是因为 data.table 中数据的

Longitude
latitude
分别在 -180/180 和 -90/90 之间,但是 Mollweide 投影中的世界扩展在这些限制内:
xmin: -17601620 ymin: -9018991 xmax: 17601620 ymax: 8751339

© www.soinside.com 2019 - 2024. All rights reserved.