[R] adding points to a wireframe
Jarrett Byrnes
byrnes at msi.ucsb.edu
Wed Aug 19 00:55:49 CEST 2009
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
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?
Thanks.
More information about the R-help
mailing list