forked from jonasstein/R-Reference-Card
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathR-refcard.tex
More file actions
763 lines (433 loc) · 24.1 KB
/
R-refcard.tex
File metadata and controls
763 lines (433 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
\documentclass[8pt,landscape]{article}
%\usepackage{pslatex}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{calc}
\usepackage{color}
\usepackage{wrapfig}
\usepackage{hyperref}
\usepackage[]{url}
\hypersetup{%
colorlinks=true,
linkcolor = black,
citecolor = black,
urlcolor = blue,
pdfpagemode=UseNone,
pdfstartview=FitH,
pdfauthor= {Jonas Stein, Tom Short, Emanuel Paradis},
pdftitle= R Reference Card
}
\urlstyle{same}
% Turn off header and footer
\pagestyle{empty}
%\setlength{\leftmargin}{0.75in}
\setlength{\oddsidemargin}{-0.75in}
\setlength{\evensidemargin}{-0.75in}
\setlength{\textwidth}{10.5in}
\setlength{\topmargin}{-0.3in}
\setlength{\textheight}{7.4in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth
% Redefine section commands to use less space
\makeatletter
\renewcommand\section{\@startsection{section}{1}{0mm}%
{-24pt}% \@plus -12pt \@minus -6pt}%
{0.5ex}%
{\color{blue}\normalfont\large\bfseries}}
\makeatother
% Don't print section numbers
\setcounter{secnumdepth}{0}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt}
\newcommand{\code}{\texttt}
\newcommand{\bcode}[1]{\texttt{\textbf{#1}}}
\newcommand\F{\code{FALSE}}
\newcommand\T{\code{TRUE}}
%\newcommand{\hangpara}[2]{\hangindent#1\hangafter#2\noindent}
%\newenvironment{hangparas}[2]{\setlength{\parindent}{\z@}\everypar={\hangpara{#1}{#2}}}
\newcommand{\describe}[1]{\begin{description}{#1}\end{description}}
% -----------------------------------------------------------------------
\begin{document}
%\raggedright
\footnotesize
\begin{multicols*}{3}
% multicol parameters
% These lengths are set only within the two main columns
%\setlength{\columnseprule}{0.25pt}
\setlength{\premulticols}{1pt}
\setlength{\postmulticols}{1pt}
\setlength{\multicolsep}{1pt}
\setlength{\columnsep}{2pt}
\begin{center}
{\Large\textbf{\color{blue}R Basic Reference Card}}
\end{center}
%
%Examples in this document use the variables \code{df} = data frame object,
%\code{v} = vector, \code{s} = string, \code{f} = filename as string all others are not yet rewritten.
%
%\section{Getting help}
\vspace{-2ex}
\bcode{?topic} documentation on \code{topic}
\bcode{help.search("topic")} search the help system
\bcode{apropos("topic")} all objects matching the reg. exp. "topic"
\bcode{ls()} list all objects; \code{pat="pat"} to search on a pattern
\vspace{-7ex}
\section{Input and output}
\everypar={\hangindent=9mm}
\bcode{source("my.R")} includes and executes my.R in this place
\bcode{data(f)} loads specified data sets
\bcode{install.package()}
\bcode{library(s)} load add-on packages
\bcode{read.table(f)} reads a file into data frame; \code{sep=""} for value separator; \code{header=TRUE} names on the first line; \code{as.is=TRUE}
prevent string to factor conversion
\bcode{read.csv(f,header=TRUE)} same, for comma-delimited files
\bcode{read.delim(f",header=TRUE)} same, for tab-delimited files
\bcode{read.fwf(f,widths,header=FALSE,sep="\t",as.is=FALSE)} for \emph{f}ixed \emph{w}idth \emph{f}ormatted data
\bcode{save(f,...)} saves the specified objects (...) in the XDR format
\bcode{save.image(f)} saves all objects
\bcode{load(f)} load the datasets written with \code{save}
\bcode{print(a, ...)} prints its arguments; \emph{generic} function
\bcode{format(x,...)} format an R object for pretty printing
\bcode{write.table(x, file=f,row.names=TRUE, col.names=TRUE, sep=" ")}
convert \code{x} to data frame and output to \code{f}; see params: \code{quote}, \code{sep}, \code{eol}, \code{na}, \code{col.names=NA}
\bcode{sink(f)} output to \code{f}, until \code{sink()}
\everypar={\hangindent=0mm}
Exchange tables with other apps. (Excel) via clipboard: \\
\code{df <- read.table("clipboard")}\\
\code{write.table(df,"clipboard",sep="\textbackslash t",col.names=NA)}
\section{Data creation}
\everypar={\hangindent=9mm}
\bcode{c(...)} combine arguments to vector, \emph{generic}, see param \code{recursive}
\bcode{from:to} generates a sequence;\code{2:5} returns \code{[1] 2 3 4 5}
\bcode{seq(from,to)} generates a sequence, \code{by=} set step; \code{length=} set length
\bcode{seq(along=x)} generates \code{1, 2, ..., length(x)}; useful for loops
\bcode{rep(x,n)} replicate \code{x} \code{n}-times (abcabc); \code{each=} to get (aabbcc)
\bcode{data.frame(...)} data frame from the list of vector parameters;
\code{data.frame(v=1:6,ch=c("a","B"))}; recycle shorter vectors
\bcode{list(...)} create a list of the named or unnamed arguments;
\code{list(a=c(1,2),b="hi",c=3i)};
\bcode{array(x,dim=)} array with data \code{x}; specify
dimensions like \code{dim=c(3,4,2)}; elements of \code{x} recycle if \code{x}
is not long enough
\bcode{matrix(x,nrow=,ncol=)} matrix; elements of \code{x} recycle
\bcode{outer(x,y, FUN(x,y) )} create matrix by tensor product
\bcode{factor(x,levels=)} encodes a vector \code{x} as a factor
\bcode{gl(n,k,length=n*k,labels=1:n)} factor with \code{n} labels $k$-times each
\bcode{expand.grid()} data frame of all combinations of given lists
\bcode{cbind(df1, df2), rbind(df1,df2)} combine arguments by columns/rows for matrix-like objects
\section{Object operations}
\everypar={\hangindent=9mm}
\bcode{rm(myvar)} removes object \code{myvar} from memory
\bcode{rm(list = ls(all = TRUE))} removes all objects from memory
\bcode{class(X)} class of object \code{X} (get type of data)
\bcode{as.array(x), as.data.frame(x), as.numeric(x), ...} \\
convert type; \code{methods(as)} shows a complete list
\bcode{is.na(x), is.null(x), is.array(x), is.numeric(x), ...}\\
test for type; \code{methods(is)}
\bcode{summary(a)} gives a ``summary'' of \code{a}, \emph{generic} function
\bcode{length(x)} number of elements in \code{x}
\bcode{dim(x)} get or set the dimension of an object;
\code{dim(x) <- c(3,2)}
\bcode{dimnames(x)} get or set the dimension names of an object
\bcode{nrow(x)}, \bcode{ncol(x)} number of rows/cols of matrix (cf. \code{NROW}, \code{NCOL})
%\bcode{class(x)} get or set the class of \code{x}; \code{class(x) <- "myclass"}
%\bcode{unclass(x)} remove the class attribute of \code{x}
%\bcode{attr(x,which)} get or set the attribute \code{which} of \code{x}
%\bcode{attributes(obj)} get or set the list of attributes of \code{obj}
\section{addressing vectors}
\begin{tabular}{@{}l@{\ \ \ }l}
\code{v[n]} & \code{n}$^{th}$ element\\
\code{v[-n]} & all \emph{but} the \code{n}$^{th}$ element\\
\code{v[1:n]} & first \code{n} elements\\
\code{v[-(1:n)]} & elements from \code{n+1} to the end\\
\code{v[c(1,4,2)]} & specific elements\\
\code{v["name"]} & element named \code{"name"}\\
\code{v[v > 3 \& v < 5]} & all elements between 3 and 5\\
\code{v[v \%in\% set]} & elements in vector \code{set}
\end{tabular}
\vspace{-6ex}
\section{addressing lists}
\begin{tabular}{@{}l@{\ \ \ }l}
\code{x[n]} or \code{x[[n]]}& \code{n}$^{th}$ element of the list\\
\code{x[["name"]]} or \code{x\$name} & element of the list named \code{"name"}
\end{tabular}
\vspace{-6ex}
\section{addressing matrices and dataframes}
\begin{tabular}{@{}l@{\ \ \ }l}
\code{x[i,j]} & element at row \code{i}, column \code{j}\\
\code{x[i,]} & row \code{i}\\
\code{x[,j]} & column \code{j}\\
\code{x[,c(1,3)]} & columns 1 and 3\\
\code{x["name",]} & row named \code{"name"}\\
{\bf only for dataframes:} & \\
\code{df[["name"]]} or \code{df\$name}& column named \code{"name"}
\end{tabular}
\vspace{-6ex}
\section{Data selection and manipulation}
\everypar={\hangindent=9mm}
\bcode{which.max(v), which.min(v)} index of the max/min element of
\bcode{v}
\bcode{rev(v)} reverses the elements of \code{v}
\bcode{sort(v)} sorts \code{v} (increasing); use \code{rev(sort(x))} for decreasing
\bcode{cut(x,breaks)} divides \code{x} into intervals (laels of resulting factor)\\ \code{breaks} is number of intervals or vector of cut points
\bcode{match(x, y)} for every \code{x[i]} index of same value in \code{y}, \code{NA} otherwise
\bcode{which(x)} indices of TRUE in logical vector \code{x}; e.g. \code{which(x>7)}
\bcode{na.omit(x)} suppress \code{NA} values (or lines of matrix or data frame)
\bcode{na.fail(x)} returns an error message if \code{x} contains at least one \code{NA}
\bcode{unique(x)} suppress duplicate values (or lines of matrix or DF)
\bcode{table(x)} freqency/{\bf contingency table} for vector/data frame
\bcode{subset(df, x)} lines where \code{x} is TRUE; e.g. \code{subset(df, V1 < 5)}
\bcode{sample(x, N)} random sample of size \code{N} from vector \code{x};\code{replace=FALSE}
\bcode{prop.table(x,margin=)} table entries as fraction of marginal table
\section{Math}
\everypar={\hangindent=9mm}
\bcode{sin,cos,tan,asin,acos,atan,atan2,log,log10,exp}
\bcode{range(x)} shortcut for \code{c(min(x), max(x))}
\bcode{sum(x)} sum of the elements of \code{x}
\bcode{diff(x)} iterated differences of vector \code{x}
\bcode{prod(x)} product of the elements of \code{x}
\bcode{mean(x)} mean of the elements of \code{x}
\bcode{median(x)} median of the elements of \code{x}
\bcode{quantile(x,probs=)} sample quantiles; \code{type=} nine types of approx.
\bcode{weighted.mean(x, w)} mean of \code{x} with weights \code{w}
\bcode{rank(x)} ranks of the elements of \code{x}
\bcode{var(x)} variance of the elements of \code{x};
\bcode{sd(x)} standard deviation of \code{x}
\bcode{cov(x)} covariance matrix of the matrix or data frame\code{x}
\code{cor(x)} correlation matrix of \code{x} see param. \code{method=}
\bcode{var(x, y)} or \code{cov(x, y)} covariance between \code{x} and \code{y}
\bcode{cor(x, y)} linear correlation between \code{x} and \code{y} (also for matrices)
\bcode{choose(n, k)} $k$-combinations from $n$ elements = $n!/[(n-k)!k!]$
\bcode{round(x, n)} rounds the elements of \code{x} to \code{n}
decimals
\bcode{scale(x)} normalization of vector (matrix, df) $x$
\bcode{pmin(x,y,...)}, \bcode{pmax(x,y,...)} parallel minimum, maximum
\bcode{cumsum(v)} vector with $i^{th}$ element \code{sum(v[:i])}
\bcode{cumprod(v)}, \bcode{cummin(v)}, \bcode{cummax(v)} \dots similar
%\bcode{union(x,y)},~\bcode{intersect(x,y)},~\bcode{setdiff(x,y)},~\bcode{setequal(x,y)}, \bcode{is.element(el,set)} ``set'' functions
%\bcode{fft(v)} Fast Fourier Transform; \code{inverse=T} unnormalized inverse
%\bcode{convolve(x,y)} convolutions of two vectors (via FFT); see \code{type=}
%\bcode{filter(x,filter)} applies linear filtering to a univariate time series
\everypar={\hangindent=0mm}
Many math functions have a logical parameter \code{na.rm=FALSE} to
specify missing data (NA) removal.
\section{Matrices}
\everypar={\hangindent=9mm}
\bcode{t(x)} transpose
\bcode{diag(x)} diagonal
\bcode{\%*\%} matrix multiplication and scalar product
\bcode{solve(a,b)} solves \code{a \%*\% x = b} for \code{x}
\bcode{solve(a)} matrix inverse of \code{a}
\bcode{rowSums(x)}, \bcode{colSums(x)}, \bcode{rowMeans}, \bcode{colMeans} \\
sum/mean of rows/cols for a matrix-like object
\section{Advanced data processing}
\everypar={\hangindent=9mm}
\bcode{function( arglist ) expr} function definition; \bcode{return(value)}
\bcode{lapply(X,FUN)} apply \code{FUN} to each element of the list \code{X}
%\bcode{apply(X,MARGIN,FUN,...)} apply \code{FUN} with named arguments \code{...} to slices prependicular to dimension(s) \code{MARGIN} of array \code{X}
%\bcode{tapply(X,INDEX,FUN, ...)} apply \code{FUN} to each cell
%of a ragged array given by \code{X} with indexes \code{INDEX}
\bcode{by(data,FACTOR,FUN,...)} split data frame \code{data} by \code{FACTOR} of same length and apply \code{FUN} to
resulting data frames
\bcode{merge(a,b)} merge two data frames (default by common columns)
\bcode{ftable(xtabs(cols~rows,data=x))} a contingency table from DF
%\bcode{aggregate(df,by,FUN)} splits \code{df} into subsets, computes summary statistics for
% each, and returns the result in a convenient form; \code{by} is a
% list of grouping elements, each as long as the variables in \code{df}
\bcode{stack, unstack(x,...)} convert list of factor vectors to/from DF
%\bcode{reshape(x, ...)} reshapes a data frame between 'wide' format with
% repeated measurements in separate columns of the same record and
% 'long' format with the repeated measurements in separate records;
% use \code(direction="wide") or \code(direction="long")
%\bcode{do.call(funname, args)} executes a function call from the name of
% the function and a list of arguments to be passed to it
\section{Distributions}
\bcode{rnorm(n, mean=0, sd=1)} Gaussian (normal)
\bcode{rlnorm(n, meanlog=0, sdlog=1)} lognormal
\bcode{rweibull(n, shape, scale=1)} Weibull
\bcode{rgamma(n, shape, scale=1)} gamma
\bcode{rbeta(n, shape1, shape2)} beta
\bcode{rt(n, df)} `Student' ($t$)
\bcode{rf(n, df1, df2)} Fisher--Snedecor ($F$)
\bcode{rchisq(n, df)} Pearson ($\chi^2$)
\bcode{rexp(n, rate=1)} exponential
\bcode{rpois(n, lambda)} Poisson
\bcode{rcauchy(n, location=0, scale=1)} Cauchy
\bcode{rbinom(n, size, prob)} binomial
\bcode{rhyper(nn, m, n, k)} $nn$-white drown, $m$-white, $n$-black, $k$-drown
\bcode{rgeom(n, prob)} geometric
\bcode{rnbinom(n, size, prob)} negative binomial
\bcode{rlogis(n, location=0, scale=1)} logistic
\bcode{runif(n, min=0, max=1)} uniform
\bcode{rwilcox(nn, m, n)}, \code{rsignrank(nn, n)} Wilcoxon's statistics
\bcode{d<distr>(x, ...)} density function
\bcode{p<distr>(x, ...)} distribution (CDF)
\bcode{q<distr>(p, ...)} quantile function ($0 \le p \le 1$)
\section{Tests and confidence intervals}
\everypar={\hangindent=9mm}
\bcode{t.test()} Student's test
\bcode{pairwise.t.test()} ...corrections for ANOVA posthoc analysis
\bcode{power.t.test()} power of $t$-test
\bcode{binom.test()} exact test for $p$
\bcode{var.test()} F-test for variance of normal distribution
\bcode{fisher.test()} exact test for independence in contingency table
\bcode{ks.test()} one or two sample Kolmogorov-Smirnov test
\bcode{kruskal.test(x)} Kruskal-Wallis (``robust'' ANOVA for list \code{x})
\bcode{shapiro.test()} test of normality
\bcode{apropos("test")} for full list
\section{Statistics}
\bcode{approx(x,y=)} piecewise linear or constant interpolation
\bcode{spline(x,y=)} cubic spline interpolation
\bcode{lm(formula, data=, subset=)} fit linear model; \code{formula} is typically of
the form \code{response ~ termA + termB + ...}; use \code{I(x*y)
+ I(x\^{}2)} for terms made of nonlinear components
\bcode{aov(formula)} analysis of variance model
{\color{blue}\bf formulas}
\bcode{x+c:d} with interaction term $y=\beta_0 + \beta_x x + \beta_{cd}$;
\bcode{a-1} without intercept
\bcode{c*d} same as \code{c+d+c:d} same as \code{(c+d)\^2}
\bcode{I(x\^2)} $y=\beta_0 + \beta_2 x^2$
%\bcode{glm(formula,family=)} fit generalized linear models, specified by
% giving a symbolic description of the linear predictor and a
% description of the error distribution; \code{family} is a
% description of the error distribution and link function to
% be used in the model; see \code{?family}
%\bcode{loess(formula)} fit a polynomial surface using local fitting
{\color{blue}\bf work with \code{fit}}
\everypar={\hangindent=9mm}
\bcode{predict(fit,...)} predictions from \code{fit} based on input data
\bcode{df.residual(fit)} number of residual degrees of freedom
\bcode{coef(fit)} returns the estimated coefficients
\bcode{residuals(fit)} returns the residuals
\bcode{deviance(fit)} returns the deviance
\bcode{fitted(fit)} returns the fitted values
%\bcode{logLik(fit)} computes the logarithm of the likelihood and the number of parameters
%\bcode{AIC(fit)} computes the Akaike information criterion or AIC
\bcode{anova(fit,...)} ANOVA table
\bcode{plot(fit)}
\vspace{-6ex}
\section{Basic Plotting}
\everypar={\hangindent=9mm}
\bcode{plot(y)} plot of the values of \code{y} (on the $y$-axis) ordered on the $x$-axis
\bcode{plot(vx, vy)} scatter plot; points (\code{vx[i]}, \code{vy[i]})
\bcode{matplot(x,y)} $i^{th}$ col of matrix $x$ vs. $i^{th}$ col of $y$ taking $i^{th}$ value from vector plot params (col, bg, pch,..)
\bcode{stripchart(x)} plot of the values of \code{x} on a line
\bcode{hist(x)} histogram of the frequencies of \code{x}
\bcode{barplot(x)} histogram of the values of \code{x}; horizontal: \code{horiz=FALSE}
\bcode{pie(x)} circular pie-chart
\bcode{boxplot(x)} ``box-and-whiskers'' plot
\bcode{pairs(x)} plot for every pair of columns in data frame \code{x}
\bcode{pairs({\textasciitilde{}}V1+V2+V3,data=df)} only for columns 1,2,3
\bcode{plot.ts(x)} plot time series object \code{x}
\bcode{ts.plot(x)} multivariate series may have different dates
\bcode{qqnorm(x)} quantiles of \code{x} with respect to \code{qnorm()}
\bcode{qqplot(x, y)} quantiles of \code{y} with respect to the quantiles of \code{x}
\bcode{contour(x, y, z)} \code{x}, \code{y} - vectors; \code{z}$=z(x,y)$
\bcode{filled.contour(x, y, z)} same + fill between contours
\bcode{image(x, y, z)} plot $z$ as colour
\bcode{persp(x, y, z)} 3D graph with perspective
\bcode{dotchart(x)} Cleveland's plot, cf. dotchart2 from package Hmisc
\bcode{stars(x)} draw star for every row of df \code{x}; \code{draw.segments=}
\bcode{coplot(x\~{}y $\mid$ z)} conditioning scatter plots for each value or interval of values of \code{z}
\bcode{symbols(x, y, ...)} draw parametic symbols (termometer, circle, ...) at \code{x},\code{y} points
\section{Statistic Plotting}
\bcode{fourfoldplot(x)} plot 2 by 2 by k contingency table $x$visualizes, with quarters of circles, the association between two dichotomous variables for different populations (\code{x} must be an array with \code{dim=c(2, 2, k)}, or a matrix with \code{dim=c(2, 2)} if $k=1$)
\bcode{assocplot(x)} Cohen--Friendly graph showing the deviations from independence of rows and columns in a two dimensional contingency table
\bcode{mosaicplot(x)} `mosaic' graph of the residuals from a log-linear regression of a contingency table
\bcode{interaction.plot (f1, f2, y)} plot means of \code{y} ($y$-axis) for factors \code{f1} ($x$-axis) and \code{f2} (line type)
\bcode{termplot(mod.obj)} plot (partial) effects of a regression model
\vspace{-5ex}
\section{Low-level plotting commands}
\everypar={\hangindent=9mm}
\bcode{points(x, y)} adds points (the option \code{type=} can be used)
\bcode{lines(x, y)} id. but with lines
\bcode{text(x, y, labels, ...)} add text \code{labels} at points (\code{x}, \code{y})
\bcode{mtext(text, side=3, ...)} add \code{text} at margin specified by \code{side}
\bcode{segments(x0, y0, x1, y1)} lines from (\code{x0},\code{y0}) to (\code{x1},\code{y1})
\bcode{arrows(x0, y0, x1, y1, angle= 30, code=2)} same with arrows
\bcode{abline(a,b)} draws a line of slope \code{b} and intercept \code{a}
\bcode{abline(h=y)} draws a horizontal line at ordinate \code{y}
\bcode{abline(v=x)} draws a vertical line at abcissa \code{x}
\bcode{abline(lm.obj)} draws the regression line given by \code{lm.obj}
\bcode{rect(x1, y1, x2, y2)} rectangle with corners (\code{x1}, \code{y2}) (\code{x2}, \code{y2})
\bcode{polygon(x, y)} polygon linking the points (\code{x}, \code{y})
\bcode{legend(x, y, legend)} add legend (\code{x},\code{y})
\bcode{title()} adds a title and optionally a sub-title
\bcode{axis(side, ...)} add axis on side (1=below, 2=left, 3=above, 4=right)
\bcode{rug(v)} draws the data on the $x$-axis as small vertical lines
\bcode{locator(N, type=``n'', ...)} returns coordinates ($x,y$) after the user has clicked \code{n} times on the plot; also draws symbols \code{type}
\section{common plot params}
\bcode{add=FALSE} if \T{} superposes the plot on the previous one (if it exists)
\bcode{axes=TRUE} if \F{} does not draw the axes and the box
\bcode{type="p"} specifies the type of plot, \code{"p"}: points, \code{"l"}: lines, \code{"b"}: points connected by lines, \code{"o"}: id. but the lines are over the points, \code{"h"}: vertical lines, \code{"s"}: steps, the data are represented by the top of the vertical lines, \code{"S"}: id. but the data are represented by the bottom of the vertical lines
\bcode{xlim=, ylim=} specifies the lower and upper limits of the axes, for example with \code{xlim=c(1, 10)} or \code{xlim=range(x)}
\bcode{xlab=, ylab=} annotates the axes, must be variables of mode character
\bcode{main=} main title, must be a variable of mode character
\bcode{sub=} sub-title (written in a smaller font)
\vspace{-5ex}
\section{Graphical parameters}
\everypar={\hangindent=7mm}
\bcode{par(...)} set grapics parameters globally
\bcode{adj} adjustement of text (0=left, 0.5=center, 1=right)
\bcode{bg} background color (fill); \code{colors()} list color names
\bcode{bty} box type around plot, (\code{"o"}, \code{"l"}, \code{"7"}, \code{"c"}, \code{"u"}, \code{"]"}) or \code{bty="n"} for none
\bcode{cex} scale size of texts and symbols (also: \code{cex.axis}, ...)
\bcode{col} color of symbols and lines; use color names or \code{"\#RRGGBB"};
see \code{rgb()}, \code{hsv()}, \code{gray()}, and \code{rainbow()};
\bcode{font} style of text (\code{1}: normal, \code{2}: italics, \code{3}: bold, \code{4}: bold italics)
\hbox to 0.5\linewidth {%
\vbox{%
\bcode{las} orientation of axis labels \\
\code{0}: parallel, \code{1}: horizontal,\\
\code{2}: perpendicular, \code{3}: vertical
\bcode{lty} line type:
}
\kern-4cm\includegraphics[width=4cm]{./lines.pdf}
}
\bcode{lwd} line width
\bcode{mfrow=c(nr,nc)} set matrix \code{nr} $\times$ \code{nc} of subplots
\bcode{pch} point type (integer code) or single character
and 25, or any single character within \code{""}
\samepage\includegraphics[width=8.5cm]{pch_symbol}
\bcode{ps} size of texts
\bcode{pty} plotting region type, \code{"s"}: square, \code{"m"}: maximal
\bcode{xpd} if set to \code{TRUE}, do not clip objects poking out
%\bcode{tck} tick's length as fraction of min of plot height and width
%\bcode{tcl} tick's length as fraction of text height (default \code{tcl=-0.5})
%\bcode{xaxt} if \code{xaxt="n"} the $x$-axis is set but not drawn (useful in conjonction with \code{axis(side=1, ...)})
%\bcode{yaxt} if \code{yaxt="n"} the $y$-axis is set but not drawn (useful in conjonction with \code{axis(side=2, ...)})
\section{Lattice (Trellis) graphics}
\everypar={\hangindent=9mm}
\bcode{xyplot(y\~{}x)} bivariate plots (with many functionalities)
\bcode{barchart(y\~{}x)} histogram of the values of \code{y} with
respect to those of \code{x}
\bcode{dotplot(y\~{}x)} Cleveland dot plot (stacked plots line-by-line
and column-by-column)
\bcode{densityplot(\~{}x)} density functions plot
\bcode{histogram(\~{}x)} histogram of the frequencies of \code{x}
\bcode{bwplot(y\~{}x)} ``box-and-whiskers'' plot
\bcode{qqmath(\~{}x)} quantiles of \code{x} with respect to the values expected under a theoretical distribution
\bcode{stripplot(y\~{}x)} single dimension plot, \code{x} must be numeric, \code{y} may be a factor
\bcode{qq(y\~{}x)} quantiles to compare two distributions, \code{x} must be numeric, \code{y} may be numeric, character, or factor but must have two `levels'
\bcode{splom(\~{}x)} matrix of bivariate plots
\bcode{parallel(\~{}x)} parallel coordinates plot
\bcode{levelplot(z\~{}x*y|g1*g2)} coloured plot of the values of \code{z} at the coordinates given by \code{x} and \code{y} (\code{x}, \code{y} and \code{z} are all of the same length)
\bcode{wireframe(z\~{}x*y|g1*g2)} 3d surface plot
\bcode{cloud(z\~{}x*y|g1*g2)} 3d scatter plot
%\everypar={\hangindent=0mm}
%In the normal Lattice formula, \code{y~x|g1*g2} has
%combinations of optional conditioning variables \code{g1}
%and \code{g2} plotted on separate panels. Lattice functions
%take many of the same arguments as base
%graphics plus also \code{data=} the data frame for the formula
%variables and \code{subset=} for subsetting. Use \code{panel=} to
%define a custom panel function (see \code{apropos("panel")}
%and \code{?llines}). Lattice functions return an object of class
%trellis and have to be \code{print}-ed to produce the graph. Use
%\code{print(xyplot(...))} inside functions where automatic
%printing doesn't work. Use \code{lattice.theme} and \code{lset} to
%change Lattice defaults.
\end{multicols*}
\end{document}