Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R geom_point and ggmap

Tags:

r

ggmap

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)
like image 759
user2861089 Avatar asked Sep 19 '25 11:09

user2861089


1 Answers

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

like image 159
mnel Avatar answered Sep 21 '25 02:09

mnel