Learn R Programming

inlmisc (version 0.3.2)

PlotGraph: Plot Method for Graphs

Description

This function draws a sequence of points, lines, or box-and-whiskers using specified coordinates.

Usage

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

Arguments

x, y

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

xlab

'character'. Title for x axis.

ylab

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

asp

'numeric'. 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 giving the minimum and maximum values for the x-axis.

ylim

'numeric'. Vector of length 2 giving the minimum and maximum values for the y-axis.

xn, yn

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

ylog

'logical'. If true, a logarithm scale is used for the y axis.

type

'character'. 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.

Characters in type are cycled through; such as, "pl" alternately plots points and lines.

lty

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

lwd

'numeric'. Line width

pch

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

col

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

bg

'character'. Vector of background colors for the open plot symbols given by pch = 21:25 as in points.

fill

'character'. Vector of fill colors for areas beneath (or above, direction towards 0) lines of type = "l" or type = "s".

pt.cex

'numeric'. Expansion factor for the points.

seq.date.by

'character', 'numeric', 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 3 that indicates if 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.

conversion.factor

'numeric'. A conversion factor for the 2nd-y axis.

boxwex

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

center.date.labels

'logical'. 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".

Value

Used for the side-effect of a new plot generated.

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 (-Inf, t) for left censored, (t, Inf) for right censored, (t, t) for exact, and (t1, t2) for an interval. Where infinity is represented as Inf or NA, and t is a numeric value.

See Also

matplot, boxplot

Examples

Run this code
# NOT RUN {
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")),
          type = "p", pch = 16, scientific = FALSE, conversion.factor = 3.28)

y <- data.frame(lapply(1:3, function(i) sample(n, replace = 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 <- c("red", "gold", "green")
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.05, col = col, lty = 1, pch = 15:17,
       pt.cex = 0.9, cex = 0.8, 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))
PlotGraph(d, type = "i", ylim = c(0, 5))

graphics.off()

# }

Run the code above in your browser using DataLab