# some 3D plot examples, using wireframe() in lattice # and scatter3d() in car library(car) library(lattice) mod <- lm(prestige ~ income + education, data=Prestige) mod2 <- lm(prestige ~ log(income) + education, data=Prestige) new <- expand.grid(income=seq(min(Prestige$income), max(Prestige$income), length=25), education=seq(min(Prestige$education), max(Prestige$education), length=25)) new2 <- new new$prestige <- predict(mod, new) new2$prestige <- predict(mod2, new) head(new) tail(new) dim(new) head(new2) wireframe(prestige ~ income + education, data=new, drape=TRUE) wireframe(prestige ~ income + education, data=new2, shade=TRUE, scales=list(arrows=FALSE)) new3 <- rbind(new, new2) new3$model <- factor(c(rep("A", 625), rep("B", 625))) head(new3) tail(new3) wireframe(prestige ~ income + education | model, data=new3, shade=TRUE, scales=list(arrows=FALSE), zoom=0.75) wireframe(prestige ~ income + education, groups=model, drape=TRUE, data=new3) scatter3d(prestige ~ income + education, data=Prestige) scatter3d(prestige ~ income + education, data=Prestige, fit=c("linear", "additive")) scatter3d(prestige ~ log(income) + education, data=Prestige, fit=c("linear", "additive"))