I want to fill a raster with a function of the x and y axes. My best guess was something like this:
library(ggplot2)
df <- data.frame(x = c(-20,20), y = c(-20,20))
f <- function (x, y) x * y
ggplot(df, aes(x,y)) +
stat_function(fun = f, geom="raster")
Clearly there's a workaround in creating a matrix, filling it with the values, converting that into a raster object and that into points, but is there an easier way?