I want to plot specific coordinates on a map, and then label the points. I started to use R, I came across with rworldmap package. Is it possible to label any points, not the countries?
Data format;
Company Latitude Longitude Type
C1 20.0000 30.0000 C
S2 40.0000 50.0000 S
My code;
jdat <- read.table(file.choose(), header = TRUE)
colnames(jdat) <- c("comp", "lat", "lon", "type")
library(rworldmap)
newmap <- getMap(resolution = "low")
plot(newmap, xlim = c(10,60), ylim = c(10,60), asp = 1)
jcol <- c('red', 'blue', 'green')
type <- c("C", "S", "F")
dfa <- cbind.data.frame(jcol,type)
colnames(dfa) <- c("jcol", "type")
(jdatc <- merge(jdat, dfa))
points(jdatc$lon, jdatc$lat, col = jdatc$jcol, pch = 20, cex = 1.0)
text(x=jdatc$lon,y=jdatc$lat,labels=jdatc$comp)
legend(x='topleft',legend=as.character(dfa$type),col=dfa$jcol,pch = 20)
The code works, but only 'text' command gives the error below.
Warning message:
In xy.coords(x, y, recycle = TRUE, setLab = FALSE) :
NAs arising from coercion (translation)
How can I label the points?