0

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

wrahool
  • 1,101
  • 4
  • 18
  • 42
  • 1
    Have a look at the use of `%+%` in [this example](http://stackoverflow.com/a/18293743/1036500), that helped me add multiple geoms to the ggmap object. Also, in your `aes` your don't need `lat_long_vec$lon`, just `lon` will do, since you already tell ggmap that the data object is `lat_long_vec`. – Ben Nov 20 '13 at 08:16

1 Answers1

1

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')

hyderabad

SlowLearner
  • 7,907
  • 11
  • 49
  • 80