If x and y can vary from 0 to 10, how can I plot a maths function z = x*(y^2) as an image plot or heatmap ? The x and y should come to their respective axes and z value should be shown as colour on the plot. I could find method to plot only discrete values, not a continuous function. Thanks for your help.
Asked
Active
Viewed 230 times
1 Answers
2
For example
library(emdbook)
curve3d(x*y^2,xlim=c(0,10),ylim=c(0,10),sys3d="image")
curve3d is just a wrapper (the sys3d argument gives you a range of plotting possibilities) -- more generally, you can create a function and use outer() (if it's vectorized) to create a matrix, e.g.
xvec <- yvec <- seq(0,10,length.out=41)
z <- outer(xvec,yvec,function(x,y) x*y^2)
image(xvec,yvec,z)
Ben Bolker
- 192,494
- 24
- 350
- 426