[R] Plotting sum rather than count in hexbin

Camilo Mora cmora at Dal.Ca
Sun Oct 19 10:09:28 CEST 2014


Hi everyone,

This may be a trivial solution but I would appreciate any help.

I have a database with three variables. I would like to plot the first two variables in a xy plot making the color of points proportional to the values in the third variable. Given that many points overlap, I decided to use the hexbin package, which allows aggregating the points by a third variable.
I figured out how to make the sums by hexbins but I am falling short in how to link the sums back to the hexbins and then plot the hexbins color coded by the sums?.  Below is the code so far.

Thanks,

Camilo



library(hexbin)


#generates data for three variables
dat=data.frame(    x = c(rep(1:10,3)),
                                    y = c(rep(1:10,3)),
                                    z = c(rep(1:10,3)))

#generates hexbin with the x and y variables
hbin<-hexbin(dat$x, dat$y, xbins=10, IDs=TRUE)

#sum values of points inside hexbins
SumHexBin<-hexTapply(hbin, dat$z, sum)


#the question is how to link the SumHexBin back to the hbin and then plot it color coding bins by the sums?



	[[alternative HTML version deleted]]



More information about the R-help mailing list