我正在使用ggmap绘制航点路线。
我需要在左上角的地图中添加一个文本框,其中包含代表每个航路点的名称向量。
没有关键字,只有文字的传说。做这个的最好方式是什么?我读过关于注释和传说但不确定这是最好的方法。
library(qmap)
names<-c("Name1","Name2", "Name3")
ggm <- qmap(location=map.centre,zoom = 15, maptype = 'road')
ggm +
geom_path(data=coords,aes(x=startLon,y=startLat),color="blue",size=2)+
geom_point(data=way.points,aes(x=as.numeric(X2),y=as.numeric(X1)),
size=10,color="yellow")+
geom_text(data=way.points,
aes(x=as.numeric(X2),y=as.numeric(X1), label=seq_along(X1)))
答案 0 :(得分:3)
这是来自http://bcb.dfci.harvard.edu/~aedin/courses/R/CDC/maps.html,但它使用形状,颜色和文字在右上角显示了一个合适的图例。如果您可以为您提供数据,可以根据您的具体需求进行定制。
library(ggmap) # for crime data for the example
library(qmap)
data(crime)
violent_crimes <- subset(crime, offense != "auto theft" & offense !=
"theft" & offense != "burglary")
# rank violent crimes
violent_crimes$offense <- factor(violent_crimes$offense, levels = c("robbery",
"aggravated assault", "rape", "murder"))
# restrict to downtown
violent_crimes <- subset(violent_crimes, -95.39681 <= lon & lon <=
-95.34188 & 29.73631 <= lat & lat <= 29.784)
HoustonMap <- qmap('houston', zoom = 14,color = 'bw', legend = 'topright')
HoustonMap + geom_point(aes(x = lon, y = lat,
size = offense,colour = offense),
data = violent_crimes )