2013-04-26 112 views
0

我想繪製一組座標,以世界地圖上的研究/組織爲座標,在圖例中指定。數據集的結構如下:AUTHORS | LAT | LONG 這是對應於一項研究的多個座標不相同。 是否可以繪製數字而不是符號並將它們鏈接到圖例?R:在世界地圖上繪製分組座標

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") 

我不知道如何從作者矢量中提取信息並將其作爲圖例的一部分鏈接到緯度/經度數據。它是否與points一起工作?

+1

如果我是你,我會加入一些代碼來顯示[你已經嘗試過(http://mattgemmell.com/2008/12/08/what-have-you-tried/)並確保您的示例代碼是[reproducible](http://stackoverflow.com/q/5963269/1478381)。目前情況非常模糊。 – 2013-04-26 10:23:45

回答

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) 

使用text而不是points(你可以使用points,但你將不得不選擇pch=as.character(1:9))。在這裏,我添加了參數font=2,以便它們以粗體顯示,這使得它們更清晰。
然後創造這個傳奇是相當直接的。

enter image description here