简体   繁体   English

使用R在Google Maps上标记位置

[英]Labeling locations on Google Maps using R

I have a dataframe which has three columns - Places , lat , and long . 我有一个具有三列的数据帧- Placeslat ,和long Places is a list of strings, and the lat and long values are obtained by geocoding the list. Places是一个字符串列表,而latlong值是通过对列表进行地理编码获得的。

I can plot the lat long values using 我可以使用

map + geom_point(data = lat_long_vec, aes(x = lat_long_vec$lon, y = lat_long_vec$lat), size = 3, colour = "blue",  shape = 19)

where map = map = qmap(location=someplacename, zoom = somezoomvalue) 其中map = map = qmap(location=someplacename, zoom = somezoomvalue)

However, I would like to label the points using the Places column of the dataframe. 但是,我想使用数据框的“位置”列标记点。 I have tried the following which hasn't worked. 我尝试了以下无效的方法。

map + geom_point(data = lat_long_vec, aes(x = lat_long_vec$lon, y = lat_long_vec$lat), size = 3, colour = "blue",  shape = 19) + geom_text(aes(label=lat_long_vec$Places),hjust=0, vjust=0)

Can someone help? 有人可以帮忙吗? Thanks 谢谢

I would use geom_text like this. 我会这样使用geom_text

library(ggmap)

mydf <- data.frame(lat = 17.245088, lon = 78.299744, places = c('My place name'))

ggmap(get_googlemap(center = paste(mydf$lat[1], mydf$lon[1]),
                    maptype = 'roadmap',
                    zoom = 10,
                    color = 'bw',
                    scale = 2),
                    extent = 'panel') +
      geom_point(data = mydf,
                 aes(x = lon, y = lat),
                 fill = "red",
                 colour = "black",
                 size = 3,
                 shape = 21) +
      geom_text(data = mydf,
                aes(x = lon,
                    y = lat,
                    label = places),
                color = 'blue')

海得拉巴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM