contourPlot: contourPlot

View source: R/contourPlot.R

contourPlotR Documentation

contourPlot

Description

A frequency-plot display of two variables, with frequency denoted by colors.

Usage

contourPlot(
  D,
  Ndelta = c(50, 50),
  logCounts = TRUE,
  cols = NA,
  xlim = NA,
  ylim = NA,
  xlab = NA,
  ylab = NA,
  title = NA,
  addLine = NA,
  cf = c(0, 1)
)

Arguments

D

A data.frame with at least two columns, with the first two containing the two veriables to be used as the abscissa and ordinate coordinates for the plot. These two variables should have names, and those names will be used in axis labels.

Ndelta

A two-component integer vector specifying the number of bins to use for the respective abscissa and ordinate coordinates of the display grid. The default is c(50,50).

logCounts

If TRUE (the default), logarithmic intervals are used when specifying and labeling the contours.

cols

A list of colors to use. The default is c("gray", "skyblue", "forestgreen", "darkorange", "black"). The number of colors supplied determines the number of separate contours that are shown.

xlim

A two-component numeric vector specifying the abscissa limits. The default is to use the range of the first column in the data.frame.

ylim

As for xlim but for the ordinate limits.

xlab

Character string to use for the label on the abscissa. The value can also be an R expression. Default is the name of the first variable.

ylab

Character string to use for the label on the ordinate. The value can also be an R expression. Default is the name of the second variable.

title

Title for the main part of the plot. Default is no title.

addLine

A function that specifies the ordinate as a function of the abscissa for a line to be added to the plot. The function should have arguments cf and xl, where cf is a set of coefficients to be used to calculate the ordinate and xl is the corresponding abscissa. Here is an example: cf <- coef(lm(D[,2] ~ D[,1])) aL <- function(cf, xl) return(cf[1]+cf[2]*xl) contourPlot(..., addLine=aL)

cf

The set of coefficients to be used with function addLine() if provided. Default is c(0,1).

Details

For two variables, supplied as the first two columns in a data.frame, this function divides the area spanning the range of the two variables (or a specified range) in to a grid with specified resolution and then partitions the data into bins in that grid. It then uses the R function "filled.contour()" to display the contours of the area covered by the grid as colored regions, with a legend showing the correspondence between color and number of events in each bin. The function also accepts a function argument ("addLine") that can be used to draw a line on the resulting plot, for example to denote the result of a fit to the data.

Author(s)

William Cooper

Examples

contourPlot(RAFdata[,c('RTH1', 'RTH2')])
contourPlot(RAFdata[,c('RTH1', 'RTH2')], Ndelta=c(20,20), logCount=FALSE, 
title='Comparison of Two Temperature Measurements', 
addLine=function(cf,xl){return(xl)})

NCAR/Ranadu documentation built on Jan. 27, 2023, 1:09 a.m.