问题概要。
我使用GADMTools包中的函数gadm_sf_loadCountries()和plotmap()函数创建了一张斯里兰卡地图(见下面的代码)。因此,我的地图(见下图)是gadm_sf格式的。
我的目的是将我的GPS点包含在一个名为'Blue.whale'的.csv文件中,绘制到我使用GADMTools包中的dots()函数制作的地图上。
然而,当我运行我的代码时,我收到了这个错误信息。
Error in UseMethod("dots", x) :
no applicable method for 'dots' applied to an object of
class "c('gg', 'ggplot')"
R代码。
##Load Libraries
library(GADMTools)
library(sp)
####GADMTools Version
dev.new()
bioclim2.data <- gadm_sf_loadCountries("LKA", basefile = "./", level = 1)
##Plot map
par(mfrow=c(1,1))
Sri_lanka<-plotmap(bioclim2.data)
###
Blue.whale<-readr::read_csv("Blue_Whale_GPS_Best.csv")
colnames(Blue.whale)<-c("FID", "Latitude", "Longitude")
head(Blue.whale)
##Convert the format of the data from factors to numeric
Latitude<-as.numeric(Blue.whale$Latitude)
Longitude<-as.numeric(Blue.whale$Longitude)
##Insert GPS Points
Blue.whale$Latitude<-as.double(Blue.whale$Latitude)
Blue.whale$Longitude<as.double(Blue.whale$Longitude)
dots(Sri_lanka, points=Blue.whale, color="red", size=8)
这是一个带有经度和纬度坐标的数据框架样本。总共有908行。
# A tibble: 918 x 3
FID Latitude Longitude
<dbl> <dbl> <dbl>
1 1 5.80 80.6
2 2 5.84 80.5
3 3 5.82 80.5
4 4 5.85 80.5
5 5 5.85 80.5
6 6 5.89 80.4
7 7 5.82 80.4
8 8 5.82 80.5
9 9 5.84 80.5
10 10 5.83 80.4
如果有人能帮助解决这个错误信息,那么我将深表感谢。
最良好的祝愿
地图
这可能会有帮助...
在你的问题中,有很多我不太理解的代码(可能是由不同的来源建立的)。
你的代码有一些问题。
1) dots函数中的point参数需要一个长纬度的x和y坐标数据框 这就是经度和纬度的顺序,而且都是小写的。
2)dots函数的x对象需要一个对象。gadm_sp
或 gadm_sf
3)似乎有一个未定义的对象。Blue. whale_New.
无论如何,这似乎可以做到这一点。
library(GADMTools)
Blue.whale <- data.frame(longitude = c(80.5, 80.5, 80.5, 80.5, 80.4, 80.4, 80.5, 80.5, 80.4),
latitude = c(5.84, 5.82, 5.85, 5.85, 5.89, 5.82, 5.82, 5.84, 5.83))
Sri_lanka <- gadm_sf_loadCountries("LKA", basefile = "./", level = 1)
dots(x = Sri_lanka, points = Blue.whale, color = "red", size = 3)
创建于2020-05-11,作者: 重读包 (v0.3.0)