hexbin
hexbin copied to clipboard
Using a variable instead of count does not work when plotting
I tried to change the color from the count to a different variable by using cell.at. Plotting this with grid.hexagons does not produce the expected behavior. I do not see any changes in color.
library(hexbin)
library(RColorBrewer)
# Create data
x <- rnorm(mean=1.5, 1000)
y <- rnorm(mean=1.6, 1000)
z <- sample(1:6, 1000, replace = TRUE)*100
# Make the plot
bin<-hexbin(x,
y,
xbins=40,
IDs = TRUE,
xlab = "X",
ylab = "Y")
mean_z <- hexbin::hexTapply(hbin = bin,
dat = z,
FUN = max)
custom_colramp <- function(n) { colorRampPalette(rev(hcl.colors(n)))(n) }
plot(bin, main="", colramp=custom_colramp)
grid.hexagons(dat = bin,
style = "colorscale",
use.count = FALSE,
trans = function(x){x},
mincnt = min(mean_z),
maxcnt = max(mean_z),
cell.at = mean_z)
There is only a small change (the black dots) in the top left corner, which looks like the coordinates are wrong.