Learn R Programming

inlmisc (version 0.2.4)

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 = "year",
  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[, 2:n].
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. The 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. The type of plot for each column of y, see plot function for possible types. A box-and-whisker plot is drawn when type = "box", with whiskers extending to the data extremes.
lty
integer. The 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 "s".
pt.cex
numeric. Expansion factor for the points.
seq.date.by
character, numeric, or difftime. The increment of the date sequence, see 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.

See Also

matplot, boxplot

Examples

Run this code
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, seq.date.by = "weeks", scientific = FALSE, conversion.factor = 3.28)

y <- data.frame(lapply(1:3, function(i) sample(n, replace = TRUE)))
PlotGraph(x, y, ylab = "Random number", type = "s", 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")

graphics.off()

Run the code above in your browser using DataLab