Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sm.surface3d

Adding a regression surface to an rgl plot.


Description

This function adds a regression surface, defined by a matrix of heights at a regular grid of values of two covariates, to an rgl plot. Missing values can be accommodated.

Usage

sm.surface3d(eval.points, surf, scaling, 
                    col = "green", col.mesh = "black", 
                    alpha = 0.7, alpha.mesh = 1, lit = TRUE, ...)

Arguments

eval.points

if this is a two-column matrix then each column defines the marginal grids of covariate values. Alternatively, a list with two components can also be used to handle cases where the grids are of different size.

surf

a matrix of heights corresponding to the grid of covariate values. NAs are allowed.

scaling

a function to define the scaling for the rgl plot. This function is returned by an initial call to rp.plot3d in the rpanel package.

col

the colour of the surface. If col is set to a single value, this is replicated across the two components. However, a matrix of values corresponding to the entries of surf can also be supplied.

col.mesh

the colour of the surface mesh. If col.mesh is set to a single value, this is replicated across the two components. However, a matrix of values corresponding to the entries of surf can also be supplied.

alpha

the transparency of the filled triangles defining the surface. Setting this to 0 will remove the filled triangles from the plot.

alpha.mesh

the transparency of the lines drawn across the regular grid of covariate values. Setting this to 0 will remove the lines from the plot.

lit

a logical variable which controls whether the rgl plot is lit or not.

...

other optional parameters which are passed to material3d in the rgl package.

Details

the principal motivation for this function is that is can handle missing data in regression surfaces. In particular, it can be used to plot the results of applying sm.regression. In addition, the function can be used to build up more complex plots by adding successive surfaces.

Value

a vector of length 2 containing the ids of the filled surface and lines aded to the rgl plot.

Side Effects

a surface is added to the rgl plot.

See Also

Examples

with(trawl, {
   Zone93    <- (Year == 1 & Zone == 1)
   Position  <- cbind(Longitude - 143, Latitude)
   model1 <- sm.regression(Position[Zone93,], Score1[Zone93],
        h= c(0.1, 0.1), display = "rgl", xlab="Longitude - 143")
   model2 <- sm.regression(Position[Zone93,], Score1[Zone93],
        h= c(0.2, 0.2), display = "none")
   sm.surface3d(model2$eval.points, model2$est, model1$scaling, col = "red")
})

sm

Smoothing Methods for Nonparametric Regression and Density Estimation

v2.2-5.6
GPL (>= 2)
Authors
Adrian Bowman and Adelchi Azzalini. Ported to R by B. D. Ripley <ripley@stats.ox.ac.uk> up to version 2.0, version 2.1 by Adrian Bowman and Adelchi Azzalini, version 2.2 by Adrian Bowman.
Initial release
2018-09-27

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.