我有一个名为 presence 的数据框(ScientificName、Lon 和 Lat 列)。
plot(region, col="grey", legend=F)
points(presence, pch="+", col="red")
我得到了该区域的图,但是当我运行“点”线时,我没有得到任何东西(没有错误,没有图,什么都没有)。
我预计在我的光栅地图上出现点。我确保我的地图和出现在同一个坐标参考中。
编辑: 这就是我的数据的样子。我尝试删除“scientificName”列并运行之前的代码增益,但它仍然不起作用,我没有收到任何错误。
> show(region)
class : SpatRaster
dimensions : 420, 900, 1 (nrow, ncol, nlyr)
resolution : 0.008333333, 0.008333333 (x, y)
extent : 8, 15.5, 54.5, 58 (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (EPSG:4326)
source(s) : memory
name : C_01
min value : 0
max value : 0
show(presence)
# A tibble: 1,529 × 2
decimalLatitude decimalLongitude
<dbl> <dbl>
1 55.5 10.7
2 55.7 12.2
3 55.7 11.7
4 55.4 10.5
5 56.1 10.5
6 55.8 11.4
7 55.4 11.2
8 56.1 9.57
9 56.2 10.2
10 55.9 10.1
# ℹ 1,519 more rows
# ℹ Use `print(n = ...)` to see more rows
您必须将
presence
数据框转换为 shapefile 才能将其添加到栅格地图上。您还没有提供任何数据。所以,我正在使用 terra
包中提供的数据集。
library(terra)
f <- system.file("ex/elev.tif", package="terra")
region <- rast(f)
plot(region)
presence <- data.frame(decimalLongitude=c(6.0,6.1,6.2,6.2),
decimalLatitude = c(49.7,49.8,49.9,49.6))
#convert the data frame into shapefile
m <- vect(presence, geom=c("decimalLongitude", "decimalLatitude"), crs="+proj=longlat +datum=WGS84")
plot(m, add = T)