2014-12-31 29 views
0

我正在使用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))) 

回答

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) 

enter image description here