Re: plot histogram or some other geom on ggmap object

512 views
Skip to first unread message

Brandon Hurr

unread,
Oct 17, 2012, 3:16:49 AM10/17/12
to Andrew, ggp...@googlegroups.com
I remember seeing this and found this....


Looks like it's exactly what you're after. Package is called ggsubplot. 

On Tue, Oct 16, 2012 at 10:31 PM, Andrew <wab...@gmail.com> wrote:
Hello everyone, 

I have a dataframe (myData) of species abundance with lat lon data. 


latitude     longitude     species     abundance   location

11.6129     1.2891      x           200            here

11.6129     1.2891      y          500             here

15.377      14.754      y           5000            there

15.377      14.754      z           2001            there

I can easily get a barplot of species abundance at each site like this. 

qplot(y=abundance,x=species,data=myData,geom="bar",facets=~location).

That is all well and good, but I want to plot these barplots not in a regular grid, as facets produces, plotted to a real map.  I am aware of  the lovely ggmap package and I have downloaded a google satellite image. I can overlay point data, but I can't figure out how to get a geom like a barplot to overlay on the map.  

Thanks for any help you can give. 

Andrew Barr

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

David Kahle

unread,
Oct 17, 2012, 9:38:44 AM10/17/12
to Brandon Hurr, Andrew, ggp...@googlegroups.com
Yea, I'm not sure if I understand the question correctly.  But if you'd like to use ggmap and ggsubplot, here's a basic example I cooked up based on Garrett's; I haven't played around with it very much though.

I think you'll need to think about what you want your aesthetics to be, remembering that geom_bar defaults to stat_bin as opposed to stat_identity.  For more on that, see http://docs.ggplot2.org/0.9.2.1/.

Cheers
david.

library(ggsubplot)
library(ggmap)

qmap('afghanistan', zoom = 6, maptype = 'toner', extent = 'panel') +
  geom_subplot2d(
    aes(lon, lat,
      subplot = geom_bar(aes(victim, ..count.., fill = victim))
    ), bins = c(15,12), ref = NULL, width = rel(0.8),
    data = casualties
  )

Andrew Barr

unread,
Oct 17, 2012, 10:27:25 AM10/17/12
to David Kahle, Brandon Hurr, ggp...@googlegroups.com
Yes!  Thank you David and Brandon. This is exactly what I am looking for.  I wasn't aware of the ggsubplot package, but it does precisely what I need. 

Andrew
Reply all
Reply to author
Forward
0 new messages