R:在世界地图上绘制分组坐标 [英] R: Plot grouped coordinates on world map

查看:297
本文介绍了R:在世界地图上绘制分组坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想画一个坐在世界地图上的研究/团体组织的一组坐标,在一个传说中指定。数据集的组织如下:作者| LAT | LONG
这是与一项研究相对应的多个坐标,没有差异。
是否可以绘制数字而不是符号并将其链接到图例?

 库(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)

我不知道如何从作者向量中提取信息,并将其作为图例的一部分链接到lat / long数据。是否可以使用分?

解决方案

  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)

使用文本而不是 (您可以使用,但您必须选择 pch = as.character(1:9))。这里我添加了一个参数 font = 2 ,使它们以粗体显示,这使得它们更清晰。

然后创建图例是相当简单的。 / p>


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 ?

解决方案

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.

这篇关于R:在世界地图上绘制分组坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆