Here is the R code used to create this plot:
linearRegression <- lm(Height ~ Hours, data=data)
data$linearRegression <- predict(linearRegression)
plot_ly(data) %>%
add_trace(x = ~Hours, y = ~linearRegression, z = ~Height, type = 'scatter3d', name = 'Hours vs Height',mode = 'lines', line = list(color = 'black')) %>%
add_trace(x = ~Hours, y = ~linearRegression, z = ~linearRegression, type = 'scatter3d', name = 'Linear Regression', mode = 'lines', line = list(color = 'blue')) %>%
layout(title = "Linear Regression of Height of Dough (in inches) vs Hours Risen",
scene = list(xaxis = list(title='Hours'),
yaxis = list(title='Height'),
zaxis = list(title='Height')))
As we can see, we used lm() to fit the data (similar to ggplot from earlier) and create a column in the data set called linearRegression to store the values. Next, in the plotly graph we add a trace for Hours vs Height and a trace for the linear regression we calculated earlier. After this, we add layout to give the graph a title and labels for the x axis, y axis, and z axis.