Learn R Programming

plotfunctions (version 1.4)

plotsurface: Creates a colored surface plot from data frame input.

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 = terrain.colors(50),
  ci.col = c("green", "red"),
  nCol = 50,
  add.color.legend = TRUE,
  dec = NULL,
  fit.margin = TRUE,
  ...
)

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 output of the function fvisgam is an example of a suitable list.

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

The color scheme to use for plots. One of 'topo', 'heat', 'cm', 'terrain', 'gray', 'bwr' (blue-white-red) or 'bw'. Or a list of colors such as that generated by rainbow, heat.colors colors, topo.colors, terrain.colors or similar functions. Alternatively a vector with some colors can be provided for a custom color palette.

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.

fit.margin

Logical: whether the labels of the gradient legend should be forced to fit in the margin or not.

...

Optional parameters for image and contour.

See Also

image, contour, color_contour

Other Functions for plotting: addInterval(), add_bars(), add_n_points(), alphaPalette(), alpha(), check_normaldist(), color_contour(), dotplot_error(), drawDevArrows(), emptyPlot(), errorBars(), fill_area(), getCoords(), getFigCoords(), getProps(), gradientLegend(), legend_margin(), marginDensityPlot(), plot_error(), plot_image(), sortBoxplot()

Examples

Run this code
# NOT RUN {
# From the package graphics, see help(image):
x <- 10*(1:nrow(volcano))
y <- 10*(1:ncol(volcano))
image(x, y, volcano, col = terrain.colors(100), axes = FALSE)
contour(x, y, volcano, levels = seq(90, 200, by = 5),
        add = TRUE, col = 'peru')
axis(1, at = seq(100, 800, by = 100))
axis(2, at = seq(100, 600, by = 100))
box()
title(main = 'Maunga Whau Volcano', font.main = 4)

# now with plot surface:
# first convert to data frame
tmp <- data.frame(value = as.vector(volcano), 
    x = 10*rep(1:nrow(volcano), ncol(volcano)), 
    y = 10*rep(1:ncol(volcano), each=nrow(volcano)))
plotsurface(tmp, view=c('x', 'y'), predictor='value', 
    main='Maunga Whau Volcano')

# or with gray scale colors:
plotsurface(tmp, view=c('x', 'y'), predictor='value', 
    main='Maunga Whau Volcano', color='gray')

# change color range:
plotsurface(tmp, view=c('x', 'y'), predictor='value', 
    main='Maunga Whau Volcano', zlim=c(0,200))

#' remove color and color legend:
plotsurface(tmp, view=c('x', 'y'), predictor='value', 
    main='Maunga Whau Volcano', 
    color=NULL, col=1, add.color.legend=FALSE)

# }

Run the code above in your browser using DataLab