Search code examples
rplot3drgl

Why is my 3D plot not showing up in R Studio plot viewer?


I normally don't have a problem viewing plots in RStudio (version 1.0.44), but when I try to view a 3D plot created with the "rgl" package, nothing appears in my RStudio plot viewer.

I am able to plot without a problem the plot(cars) scatterplot.

This is the code I am using:

install.packages("rgl")
library(rgl)

plot3d(iris[1:3])  # Nothing appears in RStudio plot viewer

plot(cars)  # The cars scatterplot appears in my RStudio plot viewer
dev.off()

Any ideas why this might be so and what else I should try? I am not receiving any errors when I run plot3d(iris[1:3]). I checked with head(iris[1:3]) to make sure I was loading in the iris data correctly. I've also tried changing the plot margins:

par(mar=c(4,4,4,4)

Thank you


Solution

    • "Output may be on screen using OpenGL, or to various standard 3D file formats including WebGL, PLY, OBJ, STL" ;
    • "There are two ways in which rgl scenes are normally displayed within R. The older one is in a dedicated window. In Unix-alikes this is an X11 window; it is a native window in Microsoft Windows. On MacOS, the XQuartz system (see http://xquartz.org) needs to be installed to support this."
    • "The newer way to display a scene is by using WebGL in a browser window or in the Viewer pane in RStudio. To select this, set options(rgl.printRglwidget = TRUE). Each operation that would change the scene will return a value which triggers a new WebGL display when printed."

    Documentation FTW