Following code plots a math function as a heatmap (from: How to plot a maths function as a heatmap):
xvec <- yvec <- seq(0,10,length.out=41)
z <- outer(xvec,yvec,function(x,y) x*y^2)
image(xvec,yvec,z)
How can I create this using ggplot2 geom_tile() ?
Following commands do not work:
ggplot()+geom_tile(aes(x=xvec, y=yvec, z=z))
and
zdf = data.frame(z)
ggplot(zdf)+geom_tile(aes(z=zdf))
I am surprised not to find similar question on searching. Thanks for your help.