Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: Export 3D scatterplots non-interactively

Tags:

plot

r

rgl

Creating 3D plots in R opens up an interactive window where the user can rotate the view. For example below using package rgl:

library(rgl)
plot3d(iris[,1:3],col=c("red","green","blue")[iris$Species],size=5)

enter image description here

Is there some way to set a predefined view and export the plot as a regular image. I would like to do this in an automated non-interactive manner for many datasets.

like image 924
rmf Avatar asked Jul 04 '26 20:07

rmf


1 Answers

Use scatterplot3d package.

library(scatterplot3d)
graphics.off()
png(filename = "test.png", width = 8, height = 6, units = "in", res = 300)
par(mai = c(0.5, 0.5, 0.5, 0.5))
scatterplot3d(x = iris$Sepal.Length, y = iris$Sepal.Width, z = iris$Petal.Length,
              color = c("red","green","blue")[iris$Species],
              cex.symbols = 1, pch = 19, angle = -30)
dev.off()

enter image description here

like image 114
d.b Avatar answered Jul 06 '26 11:07

d.b