Given a numeric dataset {(x_i, y_i, z_i)} with N points, one can create a scatterplot by drawing a point P_i=(x_i,y_i) for each i=1,...,N and color each point with an intensity depending on the value of z_i.
library(ggplot2)
N = 1000;
dfA = data.frame(runif(N), runif(N), runif(N))
dfB = data.frame(runif(N), runif(N), runif(N))
names(dfA) = c("x", "y", "z")
names(dfB) = c("x", "y", "z")
PlotA <- ggplot(data = dfA, aes(x = x, y = y)) + geom_point(aes(colour = z));
PlotB <- ggplot(data = dfB, aes(x = x, y = y)) + geom_point(aes(colour = z));
Assume I have created these scatterplots. What I would like to do for each dataset is to divide the plane with a grid (rectangular, hexagonal, triangular, ... doesn't matter) and color each cell of the grid with the average intensity of all the points that fall within the cell.
Additionally, suppose I have created two such plots PlotA and PlotB (as above) for two different datasets dfA and dfB. Let c_i^k be the i-th cell of plot k. I want to create a third plot such that c_i^3 = c_i^1 * c_i^2 for every i.
Thank you.
EDIT: Minimum example