You are on page 1of 6

R Reference Card 2.

0  Operators  Indexing vectors 
<‐ Left assignment, binary x[n]   nth element
Public domain, v2.0 2012-12-24. ‐> Right assignment, binary x[‐n] all but the nth element
V 2 by Matt Baggott, matt@baggott.net = Left assignment, but not recommended x[1:n] first n elements
V 1 by Tom Short, t.short@ieee.org <<‐  Left assignment in outer lexical scope; not x[‐(1:n)] elements from n+1 to end
Material from R for Beginners by permission of for beginners x[c(1,4,2)] specific elements
Emmanuel Paradis. $ List subset, binary x[ʺnameʺ] element named "name"
‐ Minus, can be unary or binary x[x > 3] all elements greater than 3
Getting help and info  + Plus, can be unary or binary x[x > 3 & x < 5] all elements between 3 and 5
help(topic) documentation on topic ~ Tilde, used for model formulae x[x %in% c(ʺaʺ,ʺifʺ)] elements in the given set
?topic same as above; special chars need quotes: for : Sequence, binary (in model formulae:  
example ?’&&’ interaction) Indexing lists 
help.search(ʺtopicʺ) search the help system; same :: Refer to function in a package, i.e, x[n]  list with elements n
as ??topic pkg::function; usually not needed x[[n]] nth element of the list
apropos(ʺtopicʺ) the names of all objects in the * Multiplication, binary x[[ʺnameʺ]]  element named "name"
search list matching the regular expression / Division, binary x$name as above (w. partial matching)
“topic” ^ Exponentiation, binary  
help.start() start the HTML version of help %x%  Special binary operators, x can be Indexing matrices 
summary(x) generic function to give a “summary” replaced by any valid name x[i,j] element at row i, column j
of x, often a statistical one %% Modulus, binary x[i,]  row i
str(x) display the internal structure of an R object %/% Integer divide, binary x[,j]  column j
ls() show objects in the search path; specify %*% Matrix product, binary x[,c(1,3)]  columns 1 and 3
pat="pat" to search on a pattern %o% Outer product, binary x[ʺnameʺ,] row named "name"
ls.str() str for each variable in the search path %x% Kronecker product, binary  
dir() show files in the current directory %in% Matching operator, binary (in model Indexing matrices data frames (same as matrices 
methods(x) shows S3 methods of x formulae: nesting) plus the following) 
methods(class=class(x)) lists all the methods to ! x logical negation, NOT x X[[ʺnameʺ]]  column named "name"
handle objects of class x x & y elementwise logical AND x$name as above (w. partial matching)
findFn() searches a database of help packages for x && y vector logical AND  
functions and returns a data.frame (sos)   x | y elementwise logical OR Input and output (I/O) 
  x || y vector logical OR  
Other R References   xor(x, y) elementwise exclusive OR R data object I/O 
CRAN task views are summaries of R resources for < Less than, binary data(x) loads specified data set; if no arg is given it
task domains at: cran.r-project.org/web/views > Greater than, binary lists all available data sets
Can be accessed via ctv package == Equal to, binary save(file,...) saves the specified objects (...) in XDR
R FAQ:  cran.r-project.org/doc/FAQ/R-FAQ.html >= Greater than or equal to, binary platform-independent binary format
R Functions for Regression Analysis, by Vito <= Less than or equal to, binary save.image(file) saves all objects
Ricci: cran.r-project.org/doc/contrib/Ricci- load(file) load datasets written with save
refcard-regression.pdf Packages 
R Functions for Time Series Analysis, by Vito install.packages(“pkgs”, lib) download and install Database I/O 
Ricci: cran.r-project.org/doc/contrib/Ricci- pkgs from repository (lib) or other external Useful packages: DBI interface between R and
refcard-ts.pdf source relational DBMS; RJDBC access to databases
R Reference Card for Data Mining, by Yanchang update.packages checks for new versions and through the JDBC interface; RMySQL interface to
Zhao: www.rdatamining.com/docs/R-refcard- offers to install MySQL database; RODBC ODBC database access;
data-mining.pdf library(pkg) loads pkg, if pkg is omitted it lists ROracle Oracle database interface driver; RpgSQL
R Reference Card, by Jonathan Baron: cran.r- packages interface to PostgreSQL database; RSQLite SQLite
project.org/doc/contrib/refcard.pdf detach(ʺpackage:pkgʺ) removes pkg from memory interface for R

R p 1 of 6
Other file I/O  array(x,dim=)  array with data x; specify Data selection and manipulation 
read.table(file), read.csv(file),  dimensions like dim=c(3,4,2); elements of x which.max(x), which.min(x) returns the index of
read.delim(“file”), read.fwf(“file”) read a recycle if x is not long enough the greatest/smallest element of x
file using defaults sensible for a matrix(x,nrow,ncol) matrix; elements of x recycle rev(x) reverses the elements of x
table/csv/delimited/fixed-width file and create a factor(x,levels) encodes a vector x as a factor sort(x) sorts the elements of x in increasing order; to
data frame from it. gl(n, k, length=n*k, labels=1:n) generate levels sort in decreasing order: rev(sort(x))
write.table(x,file), write.csv(x,file) saves x after (factors) by specifying the pattern of their levels; cut(x,breaks) divides x into intervals (factors); breaks
converting to a data frame k is the number of levels, and n is the number of is the number of cut intervals or a vector of cut
txtStart and txtStop: saves a transcript of replications points
commands and/or output to a text file expand.grid() a data frame from all combinations of match(x, y) returns a vector of the same length as x
(TeachingDemos) the supplied vectors or factors with the elements of x that are in y (NA
download.file(url) from internet   otherwise)
url.show(url) remote input Data conversion  which(x == a) returns a vector of the indices of x if
cat(..., file=ʺʺ, sep=ʺ ʺ) prints the arguments after as.array(x), as.character(x), as.data.frame(x),  the comparison operation is true (TRUE), in this
coercing to character; sep is the character as.factor(x), as.logical(x), as.numeric(x),  example the values of i for which x[i] == a (the
separator between arguments convert type; for a complete list, use argument of this function must be a variable of
print(x, ...) prints its arguments; generic, meaning it methods(as)  mode logical)
can have different methods for different objects   choose(n, k) computes the combinations of k events
format(x,...) format an R object for pretty printing Data information  among n repetitions = n!/[(n − k)!k!]
sink(file) output to file, until sink() is.na(x), is.null(x), is.nan(x); is.array(x),  na.omit(x) suppresses the observations with missing
is.data.frame(x), is.numeric(x),  data (NA)
Clipboard I/O   is.complex(x), is.character(x); for a complete na.fail(x) returns an error message if x contains at
File connections of functions can also be used to read list, use methods(is)  least one NA
and write to the clipboard instead of a file. x prints x complete.cases(x) returns only observations (rows)
Mac OS: x <‐ read.delim(pipe(“pbpaste”)) head(x), tail(x) returns first or last parts of an object   with no NA
Windows: x <‐ read.delim(ʺclipboardʺ)  summary(x) generic function to give a summary unique(x) if x is a vector or a data frame, returns a
See also read.clipboard (psych) str(x) display internal structure of the data similar object but with the duplicates suppressed
  length(x) number of elements in x table(x) returns a table with the numbers of the
Data creation  dim(x) Retrieve or set the dimension of an object; different values of x (typically for integers or
c(...) generic function to combine arguments with the dim(x) <‐ c(3,2)  factors)
default forming a vector; with recursive=TRUE dimnames(x) Retrieve or set the dimension names split(x, f) divides vector x into the groups based on f 
descends through lists combining all elements of an object subset(x, ...) returns a selection of x with respect to
into one vector nrow(x), ncol(x) number of rows/cols; NROW(x),  criteria (..., typically comparisons: x$V1 < 10); if
from:to generates a sequence; “:” has operator NCOL(x) is the same but treats a vector as a x is a data frame, the option select gives variables
priority; 1:4 + 1 is “2,3,4,5” one-row/col matrix to be kept (or dropped, using a minus)
seq(from,to) generates a sequence by= specifies class(x) get or set the class of x; class(x) <‐  sample(x, size) resample randomly and without
increment; length= specifies desired length ʺmyclassʺ; replacement size elements in the vector x, for
seq(along=x) generates 1, 2, ..., length(along); unclass(x) removes the class attribute of x sample with replacement use: replace = TRUE
useful in for loops attr(x,which) get or set the attribute which of x sweep(x, margin, stats) transforms an array by
rep(x,times) replicate x times; use each to repeat attributes(obj) get or set the list of attributes of obj sweeping out a summary statistic
“each” element of x each times; rep(c(1,2,3),2) is   prop.table(x,margin) table entries as fraction of
1 2 3 1 2 3; rep(c(1,2,3),each=2) is 1 1 2 2 3 3 marginal table
data.frame(...) create a data frame of the named or xtabs(a b,data=x) a contingency table from cross-
unnamed arguments data.frame (v=1:4, ch= classifying factors
c("a","B","c","d"), n=10); shorter vectors are replace(x, list, values) replace elements of x listed in
recycled to the length of the longest index with values
list(...) create a list of the named or unnamed  
arguments; list(a=c(1,2),b="hi", c=3);
R p 2 of 6
Data reshaping  Math  Matrices 
merge(a,b) merge two data frames by common col Many math functions have a logical parameter t(x) transpose
or row names na.rm=FALSE to specify missing data removal. diag(x) diagonal
stack(x, ...) transform data available as separate cols %*% matrix multiplication
sin,cos,tan,asin,acos,atan,atan2,log,log10,exp 
in a data frame or list into a single col solve(a,b) solves a %*% x = b for x solve(a) matrix
min(x), max(x) min/max of elements of x
unstack(x, ...) inverse of stack() inverse of a
range(x) min and max elements of x
rbind(...) , cbind(...) combines supplied matrices, rowsum(x), colsum(x) sum of rows/cols for a
sum(x) sum of elements of x
data frames, etc. by rows or cols matrix-like object (consider rowMeans(x),
diff(x) lagged and iterated differences of vector x
melt(data, id.vars, measure.vars) changes an colMeans(x))
prod(x) product of the elements of x
object into a suitable form for easy casting,
round(x, n) rounds the elements of x to n decimals
(reshape2 package) Distributions 
log(x, base) computes the logarithm of x
cast(data, formula, fun) applies fun to melted data Family of distribution functions, depending on first
scale(x) centers and reduces the data; can center only
using formula (reshape2 package) letter either provide: r(andom sample) ; p(robability
(scale=FALSE) or reduce only (center=FALSE)
recast(data, formula) melts and casts in a single density), c(umulative probability density),or
pmin(x,y,...), pmax(x,y,...) parallel
step (reshape2 package) q(uantile):
minimum/maximum, returns a vector in which
reshape(x, direction...) reshapes data frame rnorm(n, mean=0, sd=1) Gaussian (normal)  
ith element is the min/max of x[i], y[i], . . .
between ’wide’ (repeated measurements in rexp(n, rate=1) exponential 
cumsum(x), cummin(x), cummax(x), 
separate cols) and ’long’ (repeated measurements rgamma(n, shape, scale=1) gamma 
cumprod(x) a vector which ith element is the
in separate rows) format based on direction rpois(n, lambda) Poisson 
sum/min/max from x[1] to x[i]
  rweibull(n, shape, scale=1) Weibull  
union(x,y), intersect(x,y), setdiff(x,y), 
Applying functions repeatedly  rcauchy(n, location=0, scale=1) Cauchy  
setequal(x,y), is.element(el,set) “set”
(m=matrix, a=array, l=list; v=vector, d=dataframe)  rbeta(n, shape1, shape2) beta 
functions 
apply(x,index,fun) input: m; output: a or l; applies rt(n, df) ‘Student’ (t) 
Re(x) real part of a complex number
function fun to rows/cols/cells (index) of x rf(n, df1, df2) Fisher-Snedecor (F) (!!!2) 
Im(x) imaginary part
lapply(x,fun) input l; output l; apply fun to each rchisq(n, df) Pearson 
Mod(x) modulus; abs(x) is the same
element of list x rbinom(n, size, prob) binomial  
Arg(x) angle in radians of the complex number
sapply(x,fun) input l; output v; user friendly rgeom(n, prob) geometric 
Conj(x) complex conjugate
wrapper for lapply(); see also replicate() rhyper(nn, m, n, k) hypergeometric  
convolve(x,y) compute convolutions of sequences
tapply(x,index,fun) input l output l; applies fun to rlogis(n, location=0, scale=1) logistic  
 fft(x) Fast Fourier Transform of an array
subsets of x, as grouped based on index rlnorm(n, meanlog=0, sdlog=1) lognormal  
mvfft(x) FFT of each column of a matrix
by(data,index,fun) input df; output is class “by”, rnbinom(n, size, prob) negative binomial  
filter(x,filter) applies linear filtering to a univariate
wrapper for tapply runif(n, min=0, max=1) uniform 
time series or to each series separately of a
aggregate(x,by,fun) input df; output df; applies fun rwilcox(nn, m, n), rsignrank(nn, n) Wilcoxon
multivariate time series
to subsets of x, as grouped based on index. Can
 
use formula notation. Descriptive statistics 
Correlation and variance 
ave(data, by, fun = mean) gets mean (or other fun) mean(x) mean of the elements of x
cor(x) correlation matrix of x if it is a matrix or a
of subsets of x based on list(s) by   median(x) median of the elements of x
data frame (1 if x is a vector)
quantile(x,probs=) sample quantiles corresponding
cor(x, y) linear correlation (or correlation matrix)
plyr package functions have a consistent names: to the given probabilities (defaults to
between x and y
The first character is input data type, second is 0,.25,.5,.75,1)
var(x) or cov(x) variance of the elements of x
output. These may be d(ataframe), l(ist), a(rray), or weighted.mean(x, w) mean of x with weights w
(calculated on n − 1); if x is a matrix or a data
_(discard). Functions have two or three main rank(x) ranks of the elements of x
frame, the variance-covariance matrix is
arguments, depending on input: describe(x) statistical description of data (in Hmisc
calculated
a*ply(.data, .margins, .fun, ...)  package)
var(x, y) or cov(x, y) covariance between x and y, or
d*ply(.data, .variables, .fun, ...)  describe(x) statistical description of data useful for
between the columns of x and those of y if they
l*ply(.data, .fun, ...)  psychometrics (in psych package)
are matrices or data frames
Three commonly used functions with ply functions sd(x) standard deviation of x
are summarise(), mutate(), and transform()  density(x) kernel density estimates of x
R p 3 of 6
Some statistical tests df.residual(fit) returns residual degrees of freedom Strings 
cor.test(a,b) test correlation; t.test() t test;   coef(fit) returns the estimated coefficients paste(vectors, sep, collapse) concatenate vectors
prop.test(), binom.test() sign test; chisq.test() chi- (sometimes with standard-errors) after converting to character; sep is a string to
square test; fisher.test() Fisher exact test;  residuals(fit) returns the residuals separate terms; collapse is optional string to
friedman.test() Friedman test; ks.test() deviance(fit) returns the deviance separate “collapsed” results; see also str_c below
Kolmogorov-Smirnov test... use help.search(ʺtestʺ)  fitted(fit) returns the fitted values substr(x,start,stop) get or assign substrings in a
  logLik(fit) computes the logarithm of the likelihood character vector. See also str_sub below
Models   and the number of parameters strsplit(x,split) split x according to the substring split
 
Model formulas  AIC(fit), BIC(fit) compute Akaike or Bayesian grep(pattern,x) searches for matches to pattern within
Formulas use the form: response ~ termA + termB ... information criterion x; see ?regex 
Other formula operators are: influence.measures(fit) diagnostics for lm & glm gsub(pattern,replacement,x) replace pattern in x
1 intercept, meaning depdendent variable has approx(x,y) linearly interpolate given data points; x using regular expression matching; sub() is similar
its mean value when independent variables can be an xy plotting structure but only replaces the first occurrence.
are zeros or have no influence spline(x,y) cubic spline interpolation tolower(x), toupper(x) convert to lower/uppercase
: interaction term loess(formula) fit polynomial surface using local match(x,table) a vector of the positions of first
* factor crossing, a*b is same as a+b+a:b fitting matches for the elements of x among table
^ crossing to the specified degree, so optim(par, fn, method = c(ʺNelder‐Meadʺ,  x %in% table as above but returns a logical vector
(a+b+c)^2 is same as (a+b+c)*(a+b+c) ʺBFGSʺ, ʺCGʺ, ʺL‐BFGS‐Bʺ, ʺSANNʺ) pmatch(x,table) partial matches for the elements of x
‐ removes specified term, can be used to general-purpose optimization; par is initial among table
remove intercept as in resp ~ a - 1 values, fn is function to optimize (normally nchar(x) # of characters. See also str_length below
%in% left term nested within the right: a + b minimize)
%in% a is same as a + a:b nlm(f,p) minimize function f using a Newton-type stringr package provides a nice interface for string
I() operators inside parens are used literally: algorithm with starting values p functions:
I(a*b) means a multiplied by b str_detect detects the presence of a pattern; returns a
Flow control 
|  conditional on, should be parenthetical logical vector
if(cond) expr 
Formula-based modeling functions commonly take str_locate locates the first position of a pattern; returns
if(cond) cons.expr else alt.expr  
the arguments: data, subset, and na.action. a numeric matrix with col start and end.
  for(var in seq) expr 
(str_locate_all locates all matches)
Model functions  while(cond) expr repeat expr 
str_extract extracts text corresponding to the first
aov(formula, data) analysis of variance model break  
match; returns a character vector (str_extract_all
lm(formula, data) fit linear models; next 
extracts all matches)
glm(formula, family, data) fit generalized linear switch 
str_match extracts “capture groups” formed by () from
models; family is description of error distribution Use braces {} around statements
the first match; returns a character matrix with one
and link function to be used; see ?family ifelse(test, yes, no) a value with the same shape as
column for the complete match and one column for
nls(formula, data) nonlinear least-squares test filled with elements from either yes or no
each group
estimates of the nonlinear model parameters do.call(funname, args) executes a function call
str_match_all extracts “capture groups” from all
lmer(formula, data) fit mixed effects model from the name of the function and a list of
matches ; returns a list of character matrices
(lme4); see also lme() (nlme) arguments to be passed to it
str_replace replaces the first matched pattern; returns a
anova(fit, data...) provides sequential sums of
Writing functions  character vector
squares and corresponding F-test for objects
function( arglist ) expr function definition, str_replace_all replaces all matches.
contrasts(fit, contrasts = TRUE) view contrasts
missing test whether a value was specified as an str_split_fixed splits string into a fixed number of
associated with a factor; to set use:
argument to a function pieces based on a pattern; returns character matrix
contrasts(fit, how.many) <‐ value 
require load a package within a function str_split splits a string into a variable number of
glht(fit, linfct) makes multiple comparisons using a
<<‐ attempts assignment within parent environment pieces; returns a list of character vectors
linear function linfct (mutcomp)
before search up thru environments str_c joins multiple strings, similar to paste
summary(fit) summary of model, often w/ t-values
on.exit(expr) executes an expression at function end str_length gets length of a string, similar to nchar
confint(parameter) confidence intervals for one or
return(value) or invisible str_sub extracts substrings from character vector,
more parameters in a fitted model.
similar to substr
predict(fit,...) predictions from fit
R p 4 of 6
Dates and Times  Graphs  fun=mean)
Class Date is dates without times. Class POSIXct is There are three main classes of plots in R: base plots, matplot(x,y) bivariate plot of the first column of x
dates and times, including time zones. Class grid & lattice plots, and ggplot2 package. They have vs. the first one of y, the second one of x vs. the
timeDate in timeDateincludes financial centers. limited interoperability. Base, grid, and lattice are second one of y, etc.
lubridate package is great for manipulating covered here. ggplot2 needs its own reference sheet. fourfoldplot(x) visualizes, with quarters of circles,
time/dates and has 3 new object classes:   the association between two dichotomous
interval class: time between two specific instants. Base graphics  variables for different populations (x must be an
Create with new_interval() or subtract two Common arguments for base plots:   array with dim=c(2, 2, k), or a matrix with
times. Access with int_start() and int_end() add=FALSE if TRUE superposes the plot on the dim=c(2, 2) if k=1)
duration class:  time spans with exact lengths  previous one (if it exists) assocplot(x) Cohen-Friendly graph showing the
new_duration() creates generic time span axes=TRUE if FALSE does not draw the axes and deviations from independence of rows and
that can be added to a date; other functions the box columns in a two dimensional contingency table
that create duration objects start with d: type=ʺpʺ specifies the type of plot, "p": points, "l": mosaicplot(x) ‘mosaic’ graph of the residuals from
dyears(), dweeks()…   lines, "b": points connected by lines, "o": same a log-linear regression of a contingency table
period class: time spans that may not have a as previous but lines are over the points, "h": pairs(x) if x is a matrix or a data frame, draws all
consistent lengths in seconds; functions vertical lines, "s": steps, data are represented by possible bivariate plots between the columns of x
include: years(), months(), weeks(), days(), the top of the vertical lines, "S": same as plot.ts(x) if x is an object of class "ts", plot of x with
hours(), minutes(), and seconds() previous but data are represented by the bottom respect to time, x may be multivariate but the
ymd(date, tz), mdy(date, tz), dmy(date, tz) of the vertical lines series must have the same frequency and dates
transform character or numeric dates to xlim=, ylim= specifies the lower and upper limits of ts.plot(x) same as above but if x is multivariate the
POSIXct object using timezone tz (lubridate) the axes, for example with xlim=c(1, 10) or series may have different dates and must have
  xlim=range(x) the same frequency
Other time packages: zoo, xts, its do irregular time xlab=, ylab= annotates the axes, must be variables of qqnorm(x) quantiles of x with respect to the values
series; TimeWarp has a holiday database from 1980+; mode character main= main title, must be a expected under a normal distribution
timeDate also does holidays; tseries for analysis and variable of mode character qqplot(x, y) diagnostic plotr of quantiles of y vs.
computational finance; forecast for modeling sub= sub-title (written in a smaller font) quantiles of x; see also qqPlot in cars package
univariate time series forecasts; fts for faster   and distplot in vcd package
operations; tis for time indexes and time indexed Base plot functions  contour(x, y, z) contour plot (data are interpolated
series, compatible with FAME frequencies. plot(x) plot of the values of x (on the y-axis) ordered to draw the curves), x and y must be vectors and
on the x-axis z must be a matrix so that dim(z)= c(length(x),
Date and time formats are specified with:
plot(x, y) bivariate plot of x (on the x-axis) and y (on length(y)) (x and y may be omitted). See also
%a, %A Abbreviated and full weekday name.
the y-axis) filled.contour, image, and persp
%b, %B Abbreviated and full month name.
hist(x) histogram of the frequencies of x symbols(x, y, ...) draws, at the coordinates given by
%d Day of the month (01-31)
barplot(x) histogram of the values of x; use x and y, symbols (circles, squares, rectangles,
%H Hours (00-23)
horiz=TRUE for horizontal bars stars, thermometers or “boxplots”) with sizes,
%I Hours (01-12)
dotchart(x) if x is a data frame, plots a Cleveland colours . . . are specified by supplementary
%j Day of year (001-366)
dot plot (stacked plots line-by-line and column- arguments
%m Month (01-12)
by-column) termplot(mod.obj) plot of the (partial) effects of a
%M Minute (00-59)
boxplot(x) “box-and-whiskers” plot regression model (mod.obj)
%p AM/PM indicator
stripplot(x) plot of the values of x on a line (an colorRampPalette creates a color palette (use:
%S Second as decimal number (00-61)
alternative to boxplot() for small sample sizes) colfunc <- colorRampPalette(c("black",
%U Week (00-53); first Sun is day 1 of wk 1
coplot(x˜y | z) bivariate plot of x and y for each "white")); colfunc(10)
%w Weekday (0-6, Sunday is 0)
value or interval of values of z  
%W Week (00-53); 1st Mon is day 1 of wk 1
interaction.plot (f1, f2, y) if f1 and f2 are factors, Low‐level base plot arguments 
%y Year without century (00-99) Don’t use
plots the means of y (on the y-axis) with respect points(x, y) adds points (the option type= can be
%Y Year with century
to the values of f1 (on the x-axis) and of f2 used)
%z (output only) signed offset from Greenwich;
(different curves); the option fun allows to lines(x, y) same as above but with lines
-0800 is 8 hours west of
choose the summary statistic of y (by default text(x, y, labels, ...) adds text given by labels at
%Z (output only) Time zone as a character string
R p 5 of 6
coordinates (x,y); a typical use is: plot(x, y, (the box looks like the corresponding character); tck a value that specifies the length of tick-marks on
type="n"); text(x, y, names) if bty="n" the box is not drawn the axes as a fraction of the smallest of the width
mtext(text, side=3, line=0, ...) adds text given by cex a value controlling the size of texts and symbols or height of the plot; if tck=1 a grid is drawn
text in the margin specified by side (see axis() with respect to the default; the following tcl a value that specifies the length of tick-marks on
below); line specifies the line from the plotting parameters have the same control for numbers on the axes as a fraction of the height of a line of
area segments(x0, y0, x1, y1) draws lines from the axes, cex.axis, the axis labels, cex.lab, the text (by default tcl=-0.5)
points (x0,y0) to points (x1,y1) title, cex.main, and the sub-title, cex.sub xaxt if xaxt="n" the x-axis is set but not drawn (useful
arrows(x0, y0, x1, y1, angle= 30, code=2) same as col controls the color of symbols and lines; use color in conjonction with
above with arrows at points (x0,y0) if code=2, at names: "red", "blue" see colors() or as axis(side=1, ...))
points (x1,y1) if code=1, or both if code=3; angle "#RRGGBB"; see rgb(), hsv(), gray(), and yaxt if yaxt="n" the y-axis is set but not drawn (useful
controls the angle from the shaft of the arrow to rainbow(); as for cex there are: col.axis, col.lab, in conjonction with axis(side=2, ...))
the edge of the arrow head col.main, col.sub
abline(a,b) draws a line of slope b and intercept a font an integer that controls the style of text (1:
L ce graphics
Lattice functions return objects of class trellis and
abline(h=y) draws a horizontal line at ordinate y normal, 2: italics, 3: bold, 4: bold italics); as for
must be printed. Use print(xyplot(...)) inside functions
abline(v=x) draws a vertical line at abcissa x cex there are: font.axis, font.lab, font.main,
where automatic printing doesn’t work. Use
abline(lm.obj) draws the regression line given by font.sub
lattice.theme and lset to change Lattice defaults.
lm.obj las an integer that controls the orientation of the axis
In the normal Lattice formula, y x|g1*g2 has
rect(x1, y1, x2, y2) draws a rectangle with left, right, labels (0: parallel to the axes, 1: horizontal, 2:
combinations of optional conditioning variables g1
bottom, and top limits of x1, x2, y1, and y2, perpendicular to the axes, 3: vertical)
and g2 plotted on separate panels. Lattice functions
respectively lty controls the type of lines, can be an integer or
take many of the same args as base graphics plus also
polygon(x, y) draws a polygon linking the points string (1: "solid", 2: "dashed", 3: "dotted", 4:
data= the data frame for the formula variables and
with coordinates given by x and y "dotdash", 5: "longdash", 6: "twodash", or a
subset= for subsetting. Use panel= to define a custom
legend(x, y, legend) adds the legend at the point string of up to eight characters (between "0" and
panel function (see apropos("panel") and ?llines).
(x,y) with the symbols given by legend "9") that specifies alternatively the length, in
title() adds a title and optionally a sub-title points or pixels, of the drawn elements and the xyplot(y˜x) bivariate plots (with many functionalities)
axis(side, vect) adds an axis at the bottom (side=1), blanks, for example lty="44" will have the same barchart(y˜x) histogram of the values of y with
on the left (2), at the top (3), or on the right (4); effect than lty=2 respect to those of x
vect (optional) gives the abcissa (or ordinates) lwd numeric that controls the width of lines, default 1 dotplot(y˜x) Cleveland dot plot (stacked plots line-
where tick-marks are drawn mar a vector of 4 numeric values that control the by-line and column-by-column)
rug(x) draws the data x on the x-axis as small space between the axes and the border of the densityplot(˜x) density functions plot histogram(˜x)
vertical lines graph of the form c(bottom, left, top, right), the histogram of the frequencies of x bwplot(y˜x)
locator(n, type="n", ...) returns the coordinates (x, default values are c(5.1, 4.1, 4.1, 2.1) “box-and-whiskers” plot
y) after the user has clicked n times on the plot mfcol a vector of the form c(nr,nc) that partitions the qqmath(˜x) quantiles of x with respect to the values
with the mouse; also draws symbols (type="p") graphic window as a matrix of nr lines and nc expected under a theoretical distribution
or lines (type="l") with respect to optional columns, the plots are then drawn in columns stripplot(y˜x) single dimension plot, x must be
graphic parameters (...); by default nothing is mfrow same as above but the plots are drawn by row numeric, y may be a factor
drawn (type="n") pch controls the type of symbol, either an integer qq(y˜x) quantiles to compare two distributions, x
between 1 and 25, or any single char within "" must be numeric, y may be numeric, character, or
Plot parameters factor but must have two ‘levels’
1 2 3 4 5 6 7 8
These can be set globally with par(...); many can be splom(˜x) matrix of bivariate plots
passed as parameters to plotting commands. 9 10 11 12 13 14 15 parallel(˜x) parallel coordinates plot
adj controls text justification (0 left-justified, 0.5 16 ● 17 18 19 ● 20 ● 21 ● 22 23 levelplot(z˜x*y|g1*g2) coloured plot of the values
centred, 1 right-justified) of z at the coordinates given by x and y (x, y and z
bg specifies the colour of the background (ex. : 24 25 * * . X X a a ? ? are all of the same length)
bg="red", bg="blue", . . the list of the 657 ps an integer that controls the size in points of texts wireframe(z˜x*y|g1*g2) 3d surface plot
available colours is displayed with colors()) and symbols cloud(z˜x*y|g1*g2) 3d scatter plot
bty controls the type of box drawn around the plot, pty a character that specifies the type of the plotting
allowed values are: "o", "l", "7", "c", "u" ou "]" region, "s": square, "m": maximal
R p 6 of 6

You might also like