PlotGraph: Plot Graph

View source: R/PlotGraph.R

PlotGraphR Documentation

Plot Graph

Description

Draw a sequence of points, lines, or box-and-whiskers.

Usage

PlotGraph(
  x,
  y,
  xlab,
  ylab,
  main = NULL,
  asp = NA,
  xlim = NULL,
  ylim = NULL,
  xn = 5,
  yn = 5,
  ylog = FALSE,
  type = "s",
  lty = 1,
  lwd = 0.7,
  pch = NULL,
  col = NULL,
  bg = NA,
  fill = "none",
  fillcolor = NULL,
  pt.cex = 1,
  xpd = FALSE,
  seq.date.by = NULL,
  scientific = NA,
  conversion.factor = NULL,
  boxwex = 0.8,
  center.date.labels = FALSE,
  bg.polygon = NULL,
  add.grid = TRUE
)

Arguments

x, y

'Date' vector, 'numeric' vector, 'matrix', or 'data.frame'. Data for plotting where the vector length or number of rows should match. If y is missing, then x = x[, 1] and y = x[, -1].

xlab

'character' string. Title for x axis.

ylab

'character' vector of length 2. Title for the 1st and 2nd-y axes. The title for the 2nd-y axis is optional and requires conversion.factor be specified.

main

'character' string. Main title for the plot.

asp

'numeric' number. y/x aspect ratio for spatial axes. Defaults to 1 (one unit on the x-axis equals one unit on the y-axis) when r is projected, otherwise, a calculated value based on axes limits is used.

xlim

'numeric' or 'Date' vector of length 2. Minimum and maximum values for the x-axis.

ylim

'numeric' vector of length 2. Minimum and maximum values for the y-axis.

xn, yn

'integer' count. Desired number of intervals between tick-marks on the x- and y-axis, respectively.

ylog

'logical' flag. Whether a logarithm scale is used for the y axis.

type

'character' string. Plot type, possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both points and lines,

  • "s" for stair steps (default),

  • "w" for box-and-whisker,

  • "i" for interval-censored data, see "Details" section below, and

  • "n" for no plotting.

lty

'integer' vector. Line type, see par function for all possible types. Line types are used cyclically.

lwd

'numeric' number. Line width

pch

'integer' count. Point type, see points function for all possible types.

col

'character' vector or 'function'. Point or line color, see par function for all possible ways this can be specified. Colors are used cyclically.

bg

'character' vector. Background colors for the open plot symbols given by pch = 21:25 as in points.

fill

'character' string. Used to create filled area plots. Specify "tozeroy" to fill to zero on the y-axis; "tominy" to fill to the minimum y value in the plotting region; and "tomaxy" to fill to the maximum. Requires plot type = "l", "b", and "s".

fillcolor

'character' vector. Colors for basic filled area plots. Defaults to a half-transparent variant of the line color (col).

pt.cex

'numeric' number. Expansion factor for the point symbols.

xpd

'logical' flag. Whether to prevent point and (or) line symbols from being clipped to the plot region.

seq.date.by

'character' string, 'numeric' number, or 'difftime'. The increment of the date sequence, see the by argument in the seq.Date function for all possible ways this can be specified.

scientific

'logical' vector of length 1, 2, or 3, value is recycled as necessary. Whether axes labels should be encoded in nice scientific format. Vector elements correspond to the x-axis, y-axis, and second y-axis labels. Values are recycled as necessary. Missing values correspond to the current default penalty (see options("scipen")) to be applied when deciding to print numeric values in fixed or scientific notation.

conversion.factor

'numeric' number. Conversion factor for the 2nd-y axis.

boxwex

'numeric' number. Scale factor to be applied to all boxes, only applicable for box-and-whisker plots.

center.date.labels

'logical' flag. If true, date labels are horizontally centered between x-axis tickmarks.

bg.polygon

'list'. If specified, a background polygon is drawn. The polygon is described using a list of arguments supplied to the polygon function. Passed arguments include "x" and "col".

add.grid

'logical' flag. Whether to draw a rectangular grid.

Details

Interval censored data (type = "i") requires y be matrix of 2 columns. The first column contains the starting values, the second the ending values. Observations are represented using (y0, Inf) for right-censored value, (y0, y0) for exact value, and (-Inf, y1) for left-censored value, and (y0, y1) for an interval censored value. Where infinity is represented as Inf or NA, and y is a numeric value.

Value

Invisible NULL

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

See Also

AddIntervals

Examples

n <- 50L
x <- as.Date("2008-07-12") + 1:n
y <- sample.int(n, replace = TRUE)
PlotGraph(x, y, ylab = paste("Random number in", c("meters", "feet")),
          main = "Main Title", type = "p", pch = 16,
          scientific = FALSE, conversion.factor = 3.28)

y <- data.frame(lapply(1:3, function(i) sample(n, replace = TRUE)),
                stringsAsFactors = TRUE)
PlotGraph(x, y, ylab = "Random number", pch = 1,
          seq.date.by = "days", scientific = TRUE)

y <- sapply(1:3, function(i) {
  sample((1:100) + i * 100, n, replace = TRUE)
})
m <- cbind(as.numeric(x), y)
col <- GetColors(3, scheme = "bright")
PlotGraph(m, xlab = "Number", ylab = "Random number", type = "b",
          pch = 15:17, col = col, pt.cex = 0.9)
legend("topright", LETTERS[1:3], inset = 0.02, col = col, lty = 1,
       pch = 15:17, pt.cex = 0.9, cex = 0.7, bg = "white")

d <- data.frame(x = as.Date("2008-07-12") + 1:8 * 1000,
                y0 = c(NA, NA, 1, 3, 1, 4, 2, pi),
                y1 = c(1, 2, NA, NA, 4, 3, 2, pi),
                stringsAsFactors = TRUE)
PlotGraph(d, type = "i", ylim = c(0, 5), xpd = TRUE)


USGS-R/inlmisc documentation built on Sept. 17, 2022, 2:38 a.m.