r - Nice way to generate grid of points for use in 3d plots -
every want use r plot 3d graph, e.g. below.
x=seq(-3,3,0.05) y=c(); for(i in x) { y=c(y,rep(i,length(x))) } x=rep(x,length(x)) z=pmin(x,y) library(lattice) wireframe(z~x*y, shade=true, scales=list(arrows=false)) this generates plot fine

but there more natural / efficient way of generating x , y vectors? want "product" operator gives me possible pairs.
here's easy way to using expand.grid , outer:
library(lattice) x <- seq(-3,3,by=0.05) y <- seq(-3,3,by=0.05) grid <- expand.grid(x=x, y=y) dim(grid) [1] 14641 2 grid$z = with(grid, pmin(x,y)) wireframe(z ~ x*y, data=grid, shade=true, main="x=y", scales=list(arrows=false)) contourplot(z ~ x*y, data=grid, cuts=10, aspect = "iso")
Comments
Post a Comment