vrmpx
vrmpx

Reputation: 73

Draw Heatmap with ggmap?

I want to use R and ggmaps to plot a heatmap over a map of Mexico City,

I constructed a map with

g.map <- get_map(location = c(lon = -99.1393, lat = 19.3772), 
          zoom = 11, maptype = 'roadmap')
map <- ggmap(g.map)

I have a data frame of latitude / longitude and number of tweets in the area, like this

     x      y    tweets
1 -99.300 19.200   1
2 -99.291 19.209   10
3 -99.282 19.218   2
4 -99.273 19.227   4
5 -99.264 19.236   5
6 -99.255 19.245   9

I can already plot a map with points representing each tweet, using

map + geom_point(aes(x=x,y=y,size=c,colour=c),data=tweets.df)

And I read on the other question that you could use geom_density2d to plot a heatmap, but the results seem a bit odd

geom_density result

So, what am I doing wrong?

Upvotes: 3

Views: 1192

Answers (1)

Roman
Roman

Reputation: 4999

You can try

map + geom_point(aes(x = x, y = y, size = c, colour = c), 
                 data = tweets.df, 
                 alpha = 0.5)

to get a cheap & easy heatmap effect.

Upvotes: 1

Related Questions