3

I want to plot a ggmap in R, for example, of Australia and have a layer of data points with markers corresponding to the size specified by the following data:

sitename   lat    lon    sitenum
Sydney     -34    151    1
Melbourne  -37    144    4
Adelaide   -34    138    7

Here's my code, but it's not working...

library(ggmap)
map <- get_map(location = 'Australia', zoom = 4)
mapPoints <- ggmap(map) + geom_point(aes(x = lon, y = lat, size = sitenum), alpha = .5)
user2861089
  • 1,205
  • 4
  • 22
  • 44

1 Answers1

5

You need to pass the points as the data argument to geom_points. If they are in the data.frame pp, then the following will owrk

ggmap(map) + geom_point(data = pp, aes(x =lon, y= lat,size = sitenum), alpha=0.5)

enter image description here

mnel
  • 113,303
  • 27
  • 265
  • 254
  • Thanks a lot! Just to follow up, how do I pass the points as the data argument? Sorry, I'm brand new to R! Thanks again! – user2861089 Oct 09 '13 at 04:16
  • see the `data = pp` in `geom_point`. That is telling `geom_point` to use the data.frame `pp` to source the mapped variables. – mnel Oct 09 '13 at 05:13