I would like to build the hexbin plot where for every bin is the "ratio between class 1 and class2 points falling into this bin" is plotted (either log or not).
x <- rnorm(10000)
y <- rnorm(10000)
h <- hexbin(x,y)
plot(h)
l <- as.factor(c( rep(1,2000), rep(2,8000) ))
Any suggestions on how to implement this? Is there a way to introduce function to every bin based on bin statistics?
@cryo111's answer has the most important ingredient -
IDs = TRUE
. After that it's just a matter of figuring out what you want to do withInf
's and how much do you need to scale the ratios by to get integers that will produce a pretty plot.You can determine the number of class 1 and class 2 points in each bin by
But printing them is another story. For instance, what if there are no class 2 points in one bin? The fraction is not defined then. In addition, as far as I understand
hexbin
is just a two dimensional histogram. As such, it counts the number of points that fall into a given bin. I do not think that it can handle non-integer data as in your case.