On 8/18/09, Jarrett Byrnes <byr...@msi.ucsb.edu> wrote: > A quick question. I'm trying to plot a surface from a fitted model along > with the original points, as in the following example: > > > df<-data.frame(expand.grid(100*runif(1:100), > 100*runif(1:100))) > df$Var3<-rnorm(length(df$Var1), mean=df$Var1*df$Var2, > sd=10) > > my.lm<-lm(Var3 ~ Var1*Var2, data=df) > > my.fun<-function(x,y) predict(my.lm, data.frame(Var1=x, Var2=y), > type="response") > > df2<-data.frame(expand.grid(x=seq(1,100,10), > y=seq(1,100,10))) > df2$z<-my.fun(df2$x, df2$y) > > wireframe(z ~ x*y, data=df2, col="grey", > panel.3d.wireframe=function(x,y,z,...){ > panel.3dwire(x = x, y = y, z = z, ...) > panel.3dscatter(x=df$Var1, > y=df$Var2, > z=df$Var2, > ...) > }) > > Which I coded according to what I saw here: > http://www.nabble.com/add-points-to-wireframe-td12901155.html > http://www.nabble.com/wireframe---add-data-points-td16984174.html
You are missing the part (in the second message) where you need to rescale df$Var[123] to match the scale of x, y, z (which have been already rescaled). > However, this plots the wireframe, then puts the error message: > Error using packet 1 > 'x' and 'units' must have length > 0 > > Any thoughts on what is incorrect here? No error for me (but with wrong scales of course). Perhaps your version of R is not up to date? What does sessionInfo() give you? -Deepayan ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.