- The code for the plot on the next slide.
tree_lm <- lm(Volume ~ Height + Girth, data=trees)
ax_x <- seq(min(trees$Height), max(trees$Height), by=0.1)
ax_y <- seq(min(trees$Girth), max(trees$Girth), by=0.1)
lm_surface <- expand.grid(Height=ax_x, Girth=ax_y, KEEP.OUT.ATTRS=F)
lm_surface$Volume <- predict.lm(tree_lm, newdata=lm_surface)
lm_surface <- acast(lm_surface, Girth ~ Height, value.var="Volume")
plot_ly() %>%
add_trace(data=trees, x=~Height, y=~Girth, z=~Volume) %>%
add_trace(x=ax_x, y=ax_y, z=lm_surface, type="surface")