I am attempting to graph three 3D plots and displaying all three at the same time. For the other plots I have been using the grid.arrange function from the package gridExtra. However, I am getting an error with my 3D plots. The error I am getting reads: "Error in gList(list(xyz.convert = function (x, y = NULL, z = NULL) : only 'grobs' allowed in "gList""
My code looks somethings like this:
cont1<-data.frame(matrix(rnorm(300), nrow=10, ncol=3))
pre1<-data.frame(matrix(rnorm(300), nrow=10, ncol=3))
post1<-data.frame(matrix(rnorm(300), nrow=10, ncol=3))
library(scatterplot3d)
attach(as.data.frame(cont1))
p<-scatterplot3d(X1,X2,X3, main="3D Scatterplot")
fit <- lm(X3 ~ X1+X2)
p$plane3d(fit)
attach(as.data.frame(pre1))
l<-scatterplot3d(X1,X2,X3, main="3D Scatterplot")
fit <- lm(X3 ~ X1+X2)
l$plane3d(fit)
attach(as.data.frame(post1))
m<-scatterplot3d(X1,X2,X3, main="3D Scatterplot")
fit <- lm(X3 ~ X1+X2)
m$plane3d(fit)
require(gridExtra)
grid.arrange(p,l,m)
How can I fix this?
I am not sure that
grid.arrange
can be used with anything by ggplot2 plots... Here is a potential solution usingpar
. If you want a 1x3 arrangement setmfrow=c(1,3)
or a 3x1,mfrow=c(3,1)