1

I want to plot multiple 3D scatterplots in one window. For example, with 2D scatterplots:

# data
x1 <- rnorm(10)
y1 <- rnorm(10)
x2 <- rnorm(10)
y3 <- rnorm(10)

# two plots side-by-side in one window
par(mfrow=c(1,2))
plot(y1 ~ x1)
plot(y2 ~ x2)

I am using the package scatterplot3d, but mfrow does not seem to work:

# 3D data
z <- seq(-10, 10, 0.01)
x1 <- cos(z)
x2 <- cos(z+1)
y <- sin(z)

# try to plot side by side
par(mfrow=c(1,2))
scatterplot3d(x1, y, z)
scatterplot3d(x2, y, z)

Instead of appearing side-by-side, the second plot appears on top of the first plot. How can I put multiple 3D scatterplots in one plot window using R, either with scatterplot3d or another package? Also, I would like to be able to put both a 3D scatterplot and other regular 2D plots in the same plot window.

SlowLoris
  • 995
  • 6
  • 28
  • In my env (R 3.3.2; both Rstudio and raw R; Windows), `mfrow()` works with `scatterplot3d`. Maybe it depend on environment. – cuttlefish44 Nov 09 '16 at 00:30

1 Answers1

4

You can use layout instead of mfrow. For example:

layout(matrix(c(1, 2), 1)

z <- seq(-10, 10, 0.01)
x <- cos(z)
y <- sin(z)
scatterplot3d(x, y, z, highlight.3d=TRUE, col.axis="blue",
              col.grid="lightblue", main="scatterplot3d - 1", pch=20)
scatterplot3d(x, y, z, highlight.3d=TRUE, col.axis="blue",
              col.grid="lightblue", main="scatterplot3d - 1", pch=20)]

enter image description here

Istrel
  • 2,508
  • 16
  • 22
  • This did not work for me due to typos. This should work: ```layout(matrix(c(1, 2), 1)) z <- seq(-10, 10, 0.01) x <- cos(z) y <- sin(z) scatterplot3d(x, y, z, highlight.3d=TRUE, col.axis="blue", col.grid="lightblue", main="scatterplot3d - 1", pch=20) scatterplot3d(x, y, z, highlight.3d=TRUE, col.axis="blue", col.grid="lightblue", main="scatterplot3d - 1", pch=20)``` – LuleSa Aug 29 '23 at 17:08