High level plot commands open a graphics device. High level plot elements add objects. R plot parameters ensure actual control over the graphics device.
R Plot Parameters
All high level plotting functions have arguments which can be used to customize the plot. barplot(), for example, has arguments to control bar width, styles, etc. High level functions also take the optional “three dots” argument, which allows for argument sharing. The most common arguments shared are low level graph parameters from the par() function.
The tables below define graphical parameters by type. The most commonly used are highlighted with †. The example notation c denotes one character for input; i, j, m, and n are integers; L is a logical value; x requires a numeric data object as input:
Layout Parameters
Argument | Description | Example |
---|---|---|
din | Absolute device size in inches. | c(x1, y1) |
fig | Define figure region as a fraction of device region. | c(x1, x2, y1, y2) |
fin | Absolute figure size as fraction of the device service. | c(width, height) |
fty | Figure Type; to control shape of plot; m=(default) maximal; s=square; r=arranged by rows; c=arranged by columns. | c |
mfg † | Multiple figure graphics; gives the row and column count. | c(i, j, m, n) |
mfcol | mfg plots drawn column by column (N-folding ). | !ERROR! unexpected comma |
mfrow | mfg plots drawn row by row (Z-folding). | !ERROR! unexpected comma |
Plot Formatting
Argument | Description | Example |
---|---|---|
col † | Color, device dependent (see notes below for color wheel choices). | x |
lty † | Line Type; 1=solid, 2 and up is dotted or dashed. | x |
lwd † | Line width; 1=standard; all others are multiple of default. | x |
Margins
Argument | Description | Example |
---|---|---|
mai | Margin size in inches. | c(xbot, xlef, xtop, xrig) |
mar | Margin size in text font size; default = c(5, 4, 4, 2) + 0.1 | c(xbot, xlef, xtop, xrig) |
mex | Co-ordinate unit for addressing locations in the margin. | x |
oma | Define outer margin in terms of text lines. | c(xbot, xlef, xtop, xrig) |
omd | Define outer margin as fraction of device region. | c(x1,x2,y1,y2) |
omi | Define outer margin in terms of inches. | c(xbot, xlef, xtop, xrig) |
Plot Area
Argument | Description | Example |
---|---|---|
bty | Type of box; o=full (deflault), l=mar(1,2),7=mar(3,4); c=mar(3,2,1). | c |
pin | Width and height of plot in inches. | c(width, height) |
pty | Type of plot region; s=square; m=max size (no margins). | c |
uin | Inches per usi unit. | c(x1, x2) |
usr | User coordinate limits (min, max) on the x/y axies: default=c(0,1,0,1). | c(x1, x2, y1, y2) |
xpd | Clipping; FALSE means no points/lines outside plot area. | L |
xlim † | Min/max x-axis values. | c(x1, x2) |
ylim † | Min/max v-axis values | c(y1, y2) |
Axes
Argument | Description | Example |
---|---|---|
at | Placement of tick marks; often used with pretty(). | x |
axis | If axes=T, an enclosing box, tick marks and axis labels are plotted. | L |
exp | Labels format: 0 is exponential, 1 #s on one line, 2 (default) 2*10^6 | x |
lab | Desired # of tic intervals on x or y-axis and label length | c(x, y, llen) |
labels | Axis labels | x |
las | Style of axis labels; 0=parallel to axis (default); 1=horiz; 2=perp. | x |
log | Margin for the axis title, labels and line; default=c(3,1,0). | c |
mgp | Margin for the axis title, labels and line; default=c(3,1,0). | c(x1, x2, x3) |
tck †† | Tick mark length; negative=outside the plot region (default=−0.02); if tck=1 then gridlines result; embedded in x or y axis function. | x |
xaxp / yaxp | Co-ordinates lower tick u1, upper tick uh and the # of intervals n | c(ul, uh, n) |
xaxs / yaxs † | Axis interval; s and e are standard and extended (>data values); i is axis label < data values; r range + 4%; d is direct (no change). | c |
xaxt / yaxt | Axis type; n=null; s=standard, t=time, l=log. | c |
Text and Symbols
Argument | Description | Example |
---|---|---|
adj | String justification; 0=left, 1=right, ,5=center. | x |
cex † | Character size and expansion. | x |
csi | Font height. | x |
exp | Notation; 0=exp base e, 1=exp one line, 2=exp (default: 2*10^6 format). | x |
font | Font number (device dependent). | i |
main † | Primary title | title(main = ”string”) |
pch † | # of the plot symbol or ‘c’ for character (see format table below). | n or c |
smo | Smoothness of curves; # rasters for straight line aprox; 8 is the min. | x |
srt | String rotation in degrees. | x (e.g. 90) |
sub † | Secondary title | title(sub = ”string”) |
type † | type of plot desired (see table above) | c |
xlab † | x-axis label | string |
ylab † | y-axis label | string |
Plot Symbols
Plot symbols are displayed below with their pch=n code:
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 |
# Plot Symbols # Define symbol list sym.seq <- 0:29 sym.list <- as.list(sym.seq) sym.list[27:30] <- as.list(c("+", "o", "#", "*")) # Configure graphical device n.sym <- length(sym.seq) n.row <- floor(sqrt(n.sym)) x.seq <- sym.seq %/% n.row y.seq <- 3 + (n.row-1) - sym.seq %% n.row x.coord <- range(x.seq) + c(-0.5, 0.5) y.coord <- range(y.seq) + c(-0.5, 0.5) # Create plot skeleton plot(x.coord, y.coord, type = "n", axes = FALSE, xlab = "", ylab = "", main = "Plot Symbols") # Add plot elements abline(v=x.seq, h=y.seq, col = "gray90", lty = "dotted") for(i in 1:n.sym){ sym <- sym.list[[i]] points(x.seq[i], y.seq[i], pch = sym, col = "darkgreen", bg = "gold", cex = 3) text(x.seq[i] - 0.4, y.seq[i], labels = sym, col = "red") } |
Anatomy of a Plot
A figure consists of a plot region surrounded by 4 margins:
The fundamental anatomy fields are critical to managing layout parameters. For example, the following layout diagram outlines parameters for customizing a 3×2 multi-figure graphic where mfg=c(3,2) with outer margin parameters: