SirDoctorGentleman .
2015-Oct-21 11:30 UTC
[R] Can't Get Contents and Centers of gg2plot stat_hexbin Histograms
To find the bin centers, I've tried gg2plot_build(), but the center-coordinates it provides are not what's plotted. In the below example there are several misplaced "o" symbols and some bins w/o a symbol on them. library(ggplot2) dat <- data.frame(x = rnorm(100000, 6, 2), y = rnorm(100000, 6, 2)) hexHist = ggplot(dat, aes(x, y)) + stat_binhex(bins=15); hexDat = ggplot_build(hexHist)$data[[1]] hexHistFinal = hexHist + annotate("text", hexDat$x, hexDat$y, label="o") hexHistFinal I've also given hexbin::hcell2xy(hexbin(dat$x, dat$y, 15)) a shot, but that's even further away from what's plotted. I'm not sure how to go about figuring out what data is in what bin. (My ultimate goal is to take the data in a given bin, take the averages of a third and forth column in said data, and use *annotate* to superimpose said average on a hexagonal density histogram). I've been working on this since yesterday morning with no results. :( Any ideas? [[alternative HTML version deleted]]