简体   繁体   中英

How to output the elements inside of each bins in ggplot stat_binhex()

I am trying to draw a stat_binhex graph in R. My code is below.

stat_binhex(mapping = aes(x=longitude, y=latitude), 
          data = origin_latlng, 
          color = 'white',
          alpha=0.75,
          geom = "hex", 
          position = "identity", 
          bins = 25,
          na.rm=TRUE)    
stat_binhex(mapping = aes(x=longitude, y=latitude, label = ..count.., fill = {print(sum(..count..))}), 
          data = origin_latlng, 
          color = 'white',
          alpha=0.75,
          geom = "text", 
          size = 3,
          position = "identity", 
          hjust = 0.5,
          vjust = -0.3,
          bins = 25,
          na.rm=TRUE)

origin_latlng is a data.frame of coordinates. I want to output all coordinates are inside each of hex bins. I dont know how to do it. Any help will be appreciated.

I just made it. As what 'hrbrmstr' comments, use ggplot_build(graph) to build hexgon object and extract info in it. latlng of centroids are inside of this object which makes my task become much easier. Thanks 'hrbrmstr'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM