R Base Graphics Cheat Sheet

ADVERTISEMENT

R Base Graphics Cheatsheet
ADD TEXT
SET GRAPHICAL PARAMETERS
the following can only be set with par()
location
size
par (
)
(magnification factor)
axis labels
xlab =, ylab =
all elements
cex =
plot margins oma = c
multiple
(bottom, left,
mfcol = c(nrow,ncol)
subtitle
sub =
axis labels
cex.lab =
(outer)
top, right) default:
plots
title
mfrow = c(nrow,ncol)
main =
subtitle
cex.sub =
c(0, 0, 0, 0) lines
tick mark labels cex.axis =
plot margins mar = c
style
(bottom, left,
query x & y
title
cex.main =
top, right) default:
font face
font = 1 (
par (“usr”)
plain)
limits
c(5.1, 4.1, 4.1, 2.1) lines
2
3
(bold)
(italic)
position
(bold italic)
4
CREATE A NEW PLOT
text direction
las = 1
(horizontal)
font family
family = “serif”
Bar charts
Histograms
justification
adj = 0
barplot(
height, …
)
hist(x
, …
)
.5 1
“sans” “mono”
bar labels names.arg =
breakpts
breaks =
(left, center, right)
border
border =
ADD TO AN EXISTING PLOT
fill color
col =
Line charts
plot(x
, type = “l”
)
horizontal horiz = TRUE
Add new plot [any plot function]
Lines
“blank”|0
lines (x,…)
line type
lty =
“solid”|1
(…,add = TRUE)
line style
lty =
Box plots
“dashed”|2
boxplot(x
, …
)
ex. barplot(x, add = TRUE)
line width lwd =
“dotted”|3
horizontal horizontal = TRUE
color
col =
line width
lwd =
Axes
axis (side,… )
box labels names =
Points
location
side = 1 2 3 4
points (x,…)
(bottom, left, top, right)
symbol
pch =
Dot plots
Scatterplots
)
, …
, …
dotchart(x
)
plot(x
tick mark:
dot labels
symbol
pch =
labels =
labels
labels =
REMOVE
ADJUST
location
at =
remove
tick = FALSE
color
col =
allow plotting
axis labels
ann = FALSE
rotate text
las = 1
(horizontal)
fill color
bg =
(pch: 21-25 only)
out of plot xpd = TRUE
axis, tickmarks,
Axis labels
Text
text (x, y, text,…)
xaxt = “n”
mtext (text,… )
region
and labels
yaxt = “n”
location
side = 1 2 3 4
position
pos = 1 2 3 4
(bottom, left, top, right)
(rel. to x,y)
(below, left, above, right)
aspect ratio
asp =
(default=center)
plot box
bty = “n”
lines to skip line =
(from plot
axis limits
xlim =, ylim =
region, default = 0)
Title
title (main,…)
position
x or y-coord
at =
axis labels xlab =, ylab =
NOTE: Many of the parameters here
axis lines to
xaxs = “i” ,
(depending on side)
subtitle
sub =
can be also be set in par(). See R
match
yaxs = “i”
(internal
adj = 0 .5 1
justification
title
main =
help for more options.
axis limits
axis calculation)
(left, center, right)
Joyce   R obbins,   j    

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go