My data consists of three variables: x, y, and intensity. I can create a heat map just fine with the base heatmap or ggplot's geom_tile/geom_raster (shown below). However, my x and y data is very granular (about 2000x2000), so the corresponding heat map looks quite sparse and disconnected. Is there a way to bin the x- and y- variables while retaining the intensity information, or to otherwise decrease the resolution of the heat map without discarding values?
I think I am barking up a tree something like this (How to change interpolation / smoothing in ggplot2 geom_raster), but unfortunately, that question has also gone unanswered.
ggplot(avgS4) +
geom_tile(aes(x = variable, y = V1, fill = value)) +
scale_fill_viridis(option = "magma", direction = 1, limits = c(58000,63000),
oob = squish) +
scale_y_reverse()
Sample data is shown below.
variable (x) = c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5)
V1 (y) = c(1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5)
value (intensity) = c(3,4,4,5,1,5,5,6,7,3,2,3,2,2,5,5,7,5,4,3,2,3,3,3,3)
Right now, the heat map gives each point an individual tile/square (i.e. (1,1) has an intensity of 3, (1,2) has an intensity of 4...). Is it possible to bin this data so only one square/tile on the heat map represents the four points (1,1), (1,2), (2,1), and (2,2) with the corresponding intensity of 17 (3+4+5+5)?