Learn R Programming

itsadug (version 2.0)

plotsurface: Creates a colored surface plot.

Description

This function is a wrapper around image and contour. See vignette("plotfunctions") for an example of how you could use image and contour.

Usage

plotsurface(data, view, predictor = NULL, valCI = NULL, main = NULL,
  xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, zlim = NULL,
  col = NULL, color = topo.colors(50), ci.col = c("red", "green"),
  nCol = 50, add.color.legend = TRUE, dec = NULL, ...)

Arguments

data
Data frame or list with plot data. A data frame needs to have a column with x values, a column with y values and a column with z values. A list contains a vector with unique x values, a vector with unique y values, and a matrix with z-values. The outpu
view
A vector with the names or numbers of the columns to plot on the x axis and y axis respectively.
predictor
Optional: the name of the column in the data frame data that provides the z-values. If data contains more than one column besides the x- and y-values, the predictor should be provided.
valCI
Optional: the name of the column in the data frame data that provides the CI-values. If not NULL, CI contour lines will be plotted.
main
Text string, an overall title for the plot.
xlab
Label for x axis. Default is name of first view variable.
ylab
Label for y axis. Default is name of second view variable.
xlim
x-limits for the plot.
ylim
y-limits for the plot.
zlim
z-limits for the plot.
col
Color for the contour lines and labels.
color
a list of colors such as that generated by rainbow, heat.colors colors,
ci.col
Two-value vector with colors for the lower CI contour lines and for the upper CI contour lines.
nCol
The number of colors to use in color schemes.
add.color.legend
Logical: whether or not to add a color legend. Default is TRUE. If FALSE (omitted), one could use the function gradientLegend to add a legend manually at any position.
dec
Numeric: number of decimals for rounding the color legend. When NULL (default), no rounding. If -1 (default), automatically determined. Note: if value = -1 (default), rounding will be applied also when zlim is provided.
...
Optional parameters for image and contour.

See Also

image, contour, color_contour

Other Functions for plotting: addInterval, add_bars, alphaPalette, alpha, check_normaldist, color_contour, dotplot_error, drawArrows, emptyPlot, errorBars, fadeRug, fill_area, getCoords, getFigCoords, getProps, gradientLegend, marginDensityPlot, plot_error, plot_image, rug_model

Examples

Run this code
data(simdat)

# Model with interaction:
m1 <- bam(Y ~ s(Time) + s(Trial)
+ti(Time, Trial),
data=simdat)

# get partial prediction of the ti-term:
pp <- get_modelterm(m1, select=3, as.data.frame=TRUE)
head(pp)

# plot surface:
plotsurface(pp, view=c('Time', "Trial"), predictor='fit')
# ...is the same as:
pvisgam(m1,view=c('Time', "Trial"), select=3)

# add main effects of Time and Trial:
pp1  <- get_modelterm(m1, select=1, as.data.frame=TRUE)
pp2  <- get_modelterm(m1, select=2, as.data.frame=TRUE)
pp$fit.sum <- pp$fit + rep(pp1$fit, 30) + rep(pp2$fit, each=30)

plotsurface(pp, view=c('Time', "Trial"), predictor='fit.sum')
# ...is not same as fvisgam, because in previous plot the intercept 
# is not included:
fvisgam(m1, view=c('Time', "Trial"))

# This is same as fvisgam:
pp <- get_predictions(m1, cond=list(Time=seq(0,2000, length=30),
	Trial=seq(-10,10,length=30)))
plotsurface(pp, view=c('Time', "Trial"), predictor='fit', valCI='CI')

# Just contour plot:
plotsurface(pp, view=c('Time', "Trial"), predictor='fit', valCI='CI',
	main='contour',	color=NULL, col=1, add.color.legend=FALSE)

Run the code above in your browser using DataLab