Reputation: 1141
I have a dataframe which has three columns - Places
, lat
, and long
. Places
is a list of strings, and the lat
and long
values are obtained by geocoding the list.
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)
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
Upvotes: 0
Views: 956
Reputation: 7997
I would use geom_text
like this.
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')
Upvotes: 1