13.8 Adding a Prediction Surface to a Three-Dimensional Plot

13.8.1 Problem

You want to add a surface of predicted value to a three-dimensional scatter plot.

13.8.2 Solution

First we need to define some utility functions for generating the predicted values from a model object:

With these utility functions defined, we can make a linear model from the data and plot it as a mesh along with the data, using the surface3d() function, as shown in Figure 13.17:

A 3D scatter plot with a prediction surface

Figure 13.17: A 3D scatter plot with a prediction surface

13.8.4 See Also

For more on changing the appearance of the surface, see ?rgl.material.