hexbin icon indicating copy to clipboard operation
hexbin copied to clipboard

Using a variable instead of count does not work when plotting

Open sw-jakobgepp opened this issue 1 year ago • 0 comments

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)

Screenshot 2024-08-30 at 17 17 10
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. Screenshot 2024-08-30 at 17 18 23

sw-jakobgepp avatar Aug 30 '24 15:08 sw-jakobgepp