R: Plot grouped coordinates on world map

风流意气都作罢 提交于 2019-12-12 03:55:11

问题


I would like to plot a set of coordinates organized in studies/groups on a world map, specified in a legend. The dataset is organized as follows: AUTHORS | LAT | LONG The are multiple coordinates corresponding to one study that do not differ. Is it possible to plot numbers instead of symbols and link them to a legend?

library(maps) 
library(mapdata)

test<-data.frame(Authors=(letters[1:9]), LAT=(seq(10,90,by=10)), LONG=(seq(10,90,by=10)))
map('worldHires') 
points(test$LONG,test$LAT, col="red")

I have no clue how to extract the info from the authors vector and link it to the lat/long data as part of a legend. Does it even work with points ?


回答1:


library(maps) 
library(mapdata)

test<-data.frame(Authors=(letters[1:9]), LAT=runif(9,-90,90), LONG=runif(9,-180,180))
map('worldHires') 
text(test$LONG,test$LAT,labels=1:9, col="red", font=2)
legend("bottom",legend=test$Authors, col="red", pch=as.character(1:9), bg="white", ncol=3)

Use text instead of points (you can use points but you will have to choose pch=as.character(1:9)). Here I added argument font=2 so that they appear in bold which makes them more legible.
Then creating the legend is fairly straight-forward.



来源:https://stackoverflow.com/questions/16234092/r-plot-grouped-coordinates-on-world-map

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!