How to plot 3D scatter diagram using ggplot?

Since you tagged your question with plotly and said that you’ve tried to use it with plotly, I think it would be helpful to give you a working code solution in plotly:

Creating some data to plot with:

set.seed(417)
library(plotly)
temp <- rnorm(100, mean=30, sd=5)
pressure <- rnorm(100)
dtime <- 1:100

Graphing your 3d scatterplot using plotly’s scatter3d type:

plot_ly(x=temp, y=pressure, z=dtime, type="scatter3d", mode="markers", color=temp)

Renders the following: 

ggplot as others have note, by itself does not support 3d graphics rendering.

Leave a Comment