R Quick Reference Guide
narbsy
R Quick Reference Guide
A list of generic arguments and specifics for each function type
Standard R
begin:end
produces a sequence from begin to end by ones.
c(..., recursive=FALSE)
...: objects to be concatenated
recursive: whether or not to recur into the given objects.
returns: NULL or an expression or a vector of an appropriate mode, built from concatenating objects in '...'.
`seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)),
length.out = NULL, along.with = NULL, ...)`
from: start point
to: end point
returns: a list of the defined sequence.
options:
by: default is 1; mimics c(from:to)
length.out: can be shortened; used if specified to calculate by, returning a vector of the size length.out.
along.with: a vector, the length of which is the output of seq, with by calculated using it's length.
rep(x, times=1, length.out=NA, each=1)
x: the object to repeat. may be a vector or matrix.
times: the number of times to repeat x; if x is a vector and times is a vector of the same length, x[i] is repeated times[i] times.
length.out: may be specified instead of times; will return a vector of this length.
each: each element of x is repeated each times. Treated as 1 if NA or invalid.
Graphics Library
Whole plot options
par(mfrow=c(1,1))
mfrow: a list of the number of rows and columns in the plot; the default is c(1,1) meaning 1 plot. c(rows, columns).
Plots
General arguments
color=c(""), main="", subtitle="", xlab="", ylab="", xlim=range(c()), ylim=range(c())
color: a vector of colors to be used in the plot. If fewer colors specified than colors needed for a given plot, colors are rotated in order (i.e. c("red","blue") would alternate between red and blue).
main: the title for the plot, appears on top in larger text than the other titles.
subtitle: subtitle for the plot, appears right below main at a reduced size.
xlab: the label for the x-axis.
ylab: the label for the y-axis.
xlim: the range for the x-axis; requires at least a list of start and end.
ylim: range for the y-axis; requires at least a list of start and end.
Specific plots
Bar plot
barplot(height, width, names.arg )
height: the height of the bars; if one arg given, assumed to be height
width: the width of the bars.
names.arg: a vector of labels for each bar.
Note: this command can be used to make a 1D spineplot by setting the heights to 1; using rep(1, length(x)).
Dot plot
dotchar(x, labels, pch=21)
x: vector or matrix to plot; if 1D, order is used as the y component.
labels: a vector of labels for each point. For vectors the default is to use names(x) and for matrices the row labels dimnames(x)[[1]].
pch: the plotting character to use; specified by an integer from 1 to 32.
Histogram
hist(x, breaks)
x: vector or matrix to plot
breaks: the number of bins for the histogram to use; by default it is calculated by Sturges' algorithm. Other algorithms may be specified, as well as a number of bins. One may also include a sequence or vector describing the placement of each bin.