Problem Outline:
I have created a map of Sri Lanka using the functions gadm_sf_loadCountries() and plotmap() functions in the GADMTools package (see code below). Therefore, my map (see image below) is in gadm_sf format.
My aim is to plot my GPS points contained a .csv file called 'Blue.whale' onto the map I produced using the dots() function in the GADMTools package.
However, when I run my code, I am receiving this error message:
Error in UseMethod("dots", x) :
no applicable method for 'dots' applied to an object of
class "c('gg', 'ggplot')"
R-code:
##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)
Here is a sample of the data frame with longitude and latitude coordinates. In total, there are another 908 rows
# 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
If anyone can help with this error message, then I would be deeply appreciative.
Best wishes!
Map
Blue.whale <- data.frame(....)
where ... represents a sample of values for each of the variables in the dataset which result in the error noted in your question. The section "Insert GPS Points" seems to include an undefined object:Blue.whale_New
. But I think the real problem is that your map is of classggplot
and the documentation forGADMTools::dots
requires an objectgadm_sp or gadm_sf
– Peterlongitude
andlatitude
? – Peter