R Guide

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

SCATTER PLOT

Argument Description Default


The data to be plotted. You may specify two separate vectors x and y.
Otherwise, you may specify a time series, formula, list, or matrix with
x, y two or more columns.
type A character value that specifies the type of plot: "p"
"p" points, "l" lines, "o" overplotted points and lines, "b" points joined
by lines, "s" stair steps, "h" histogram-style vertical lines, "n" no points
or lines
xlim A numeric vector with two values specifying the x limits of the plot. NULL
A character vector that specifies which axes should be plotted with a
log logarithmic scale. ""
"" neither, "x" x-axis, "y" yaxis, "xy" both
main The main title for the plot. NULL
sub The subtitle for the plot. NULL
xlab The label for the x-axis. NULL
ylab The label for the y-axis. NULL
If ann=TRUE, then axis titles and overall titles are included with plots.
ann If ann=FALSE, these annotations are not included. par("ann")
axes A logical value that specifies whether axes should be drawn. TRUE
A logical value that specifies whether a box should be drawn around
frame.plot the plot. axes
An expression that is evaluated after the axes are drawn but before
panel.first points are plotted. NULL
panel.last An expression that is evaluated after the points are plotted. NULL
asp A numeric value that specifies the aspect ratio of the plot (as y/x). NA

BAR CHARTS
Argument Description Default
Either a numeric vector or a numeric matrix representing the values to
be plotted. If values are given as a matrix and beside=FALSE, then the
bars are stacked. If beside=TRUE, then the bars are plotted next to
height each other.
width A numeric vector representing the width of the bars. 1
If beside=FALSE, a numeric value indicating the amount of space
between bars. You specify the space as a fraction of the average if(is.matrix(heig
column width. If beside=TRUE, then you can specify a two-element ht) &
vector, where the first element specifies the space within a group and beside=TRUE
space the second represents the space between groups. c(0,1) else 0.2
if(is.matrix(heig
ht))
col.names(heig
A character vector specifying the names to be plotted for each bar (or ht) else
names.arg group of bars) names(height)
A character vector or a logical value. If a logical value is given, then a
legend is generated using the row names of height. If a character
vector is given, then those character values are used instead. This
function is mostly useful when height is a matrix (and there are two
legend.text different dimensions that need labels). NULL
A logical value indicating whether columns should be stacked or
beside drawn beside each other. Only meaningful when height is a matrix. FALSE
A logical value specifying the direction to draw the bars. If
horiz=FALSE, bars are drawn vertically from left to right. If
horiz horiz=TRUE, bars are drawn horizontally from bottom to top. FALSE
A numeric value that specifies the density of shading lines in lines per
density inch. Density=NULL means that no lines are drawn. NULL
A numeric value that specifies the slope of the shading lines (in
angle degrees). 45
Gray is used if
height is a
vector; a
gamma-
corrected gray
palette if height
col A vector of colors to use for the bars (or bar components) is a matrix.
border The color to be used for the border of the bars. par("fg")
main A character value to be used as the overall title. NULL
sub A character value to be used as a subtitle. NULL
xlab A character value to use as the label for the x-axis. NULL
ylab A character value to use as the label for the y-axis. NULL
xlim Limits for the x-axis. NULL
ylim Limits for the y-axis. NULL
A logical value indicating if bars should be allowed to go outside the
xpd region. TRUE
A character value specifying whether axis scales should be
log logarithmic. ""
axes A logical value indicating whether axes should be drawn. TRUE
If axisnames=TRUE and names.arg is not null, the second axis is
axisnames drawn and labeled. TRUE
A numeric value specifying the size of numeric axis labels relative to
cex.axis other text (cex.axis=1 means full size). par("cex.axis")
A numeric value specifying the size of axis names relative to other
cex.names text. par("cex.axis")
A logical value that indicates whether to draw lines separating bars
inside when beside=TRUE. TRUE
plot A logical value indicating whether to plot the chart. TRUE
axis.lty The line type for the axis. 0
A numeric vector indicating how much bars should be shifted relative
offset to the x-axis. 0
add A logical value indicating if bars should be added to an existing plot. FALSE
args.legend A list of arguments to pass to legend (if legend.text is used). NULL

PIE CHARTS
Argument Description Default
x A vector of nonnegative numeric values that will be plotted.
An expression to generate labels, a vector of character strings, or
another object that can be coerced to a graphicAnnot object and used
labels as labels. names(x)
A numeric value indicating the number of segments used to draw the
edges outside of the pie. 200
A numeric value that specifies how big the pie should be. (Parts of the
radius pie are cut off for values over 1.) 0.8
A logical value indicating whether slices are drawn clockwise or
clockwise counterclockwise. FALSE
A numeric value specifying the starting angle for the slices (in if(clockwise) 90
init.angle degrees). else 0
A numeric value that specifies the density of shading lines in lines per
density inch. Density=NULL means that no lines are drawn. NULL
A numeric value that specifies the slope of the shading lines (in
angle degrees). 45
A numeric vector that specifies the colors to be used for slices. If
col col=NULL, then a set of six pastel colors is used. NULL
border Arguments passed to the polygon function to draw each slice. NULL
lty The line type used to draw each slice. NULL
main A character string that represents the title.

CATEGORICAL DATA
Argument Description Default
Arguments used to specify the data to plot. You may specify either a
numeric vector x containing data to plot and a vector y containing
grouping information or a formula and a data frame (data) in which to
x, y, formula, data
evaluate the formula.
A vector specifying the subset of values to be used when plotting.
subset (Only applies when using a formula and a data frame.) NULL
Logical value specifying whether the conditional densities should be
plot plotted. TRUE
A numeric vector that specifies a "tolerance parameter" for y-axis
labels. If the difference between two labels is less than this parameter,
tol.ylab they are plotted equidistantly. 0.05
A character or numeric vector that specifies the order in which levels
ylevels should be plotted. NULL
bw The "smoothing bandwidth" to use when plotting. "nrd0"
A numeric value specifying the number of points at which the density
n is estimated. 512
A numeric value specifying the lowest point at which the density is
from estimated. NULL
A numeric value specifying the highest point at which the density is
to estimated. NULL
col A vector of fill colors for the different conditional values. NULL
border Border color for shaded polygons. 1
main Main title. ""
xlab x-axis label. NULL
ylab y-axis label. NULL
yaxlabels Character vector for labeling different conditional values. NULL
xlim Range of x variables to plot. NULL
ylim Range of y variables to plot. c(0, 1)

PERSPECTIVE
Argument Description Default
x = seq(0, 1,
length.out =
Numeric vectors that explain what each dimension of z represents. nrow(z)) sy =
(Specifically, x is a numeric vector representing the x values for each seq(0, 1,
row in z, and y is a numeric vector representing the y values for each length.out =
x, y column in z.) ncol(z))
z A matrix of values to plot.
xlim = range(x)
ylim = range(y),
Numeric vectors with two values, representing the range of values to zlim = range(z,
xlim, ylim, zlim plot for x, y, and z, respectively. na.rm = TRUE)
xlab, ylab, zlab Character values specifying titles to plot for the x-, y-, and z-axes. NULL
main A character value specifying the main title for the plot. NULL
sub A character value specifying the subtitle for the plot. NULL
A numeric value that specifies the azimuthal direction of the viewing
theta angle. 0
phi A numeric value that specifies the colatitude of the viewing angle. 15
r The distance of the viewing point from the center of the plotting box. sqrt(3)
A numeric value that can be used to increase or decrease the
d perspective effect. 1
A logical value specifying whether to maintain aspect ratios when
scale plotting. TRUE
A numeric factor used to expand (when z>1) or shrink (when z<1) the z
expand coordinates. 1
col The color of the surface facets. "white"
border The color of the lines drawn around the surface facets. NULL
If specified, the surface is drawn as if illuminated from the direction
ltheta specified by azimuth ltheta and colatitude lphi. -135
lphi See the explanation for ltheta. 0
shade An exponent used to calculate the shade of the surface facets. NA
A logical value indicating whether a bounding box for the surface
box should be drawn. TRUE
axes A logical value indicating whether axes should be drawn. TRUE
nticks A numeric value specifying the number of ticks to draw on each axis. 5
ticktype A character value specifying the types of ticks drawn here. "simple"
"simple" for arrows pointing in the direction of increase, "detailed" to
show simple tick marks.

IMAGE
Argument Description Default
(Alternatively, you may pass x an argument that is a list containing
x, y elements named x, y, and z.)
z A matrix of values to plot.
Two-element numeric vectors that specify the range of values in x and
xlim, ylim y (respectively) that should be plotted.
zlim The range of values for z for which colors should be plotted.
A vector of colors to plot. Typically generated by functions like
col rainbow, heat.colors, topo.colors, or terrain.colors. heat.colors(12)
A logical value that specifies whether the plot should be added to the
add existing plot. FALSE
xlab="i",
xaxs, yaxs Style for the x- and y-axes. ylab="i"
xlab, ylab Labels for the x and y values.
An integer value specifying the number of break points for colors.
breaks (There must be at least one more color than break point.)
If oldstyle=TRUE, then the midpoints of the color intervals are equally
spaced between the limits. If oldstyle=FALSE, then the range is split
oldstyle into color intervals of equal size. FALSE

BOX PLOT
Argument Description Default
A formula of the form y~grp, where y is a variable to be plotted and
formula grp is a variable describing a set of different plotting groups.
A data frame (or list) in which the variables used in formula are
data defined.
subset A vector specifying a subset of observations to use in plotting.
x A vector specifying values to plot.
Additional vectors to plot (or graphical parameters to pass to bxp).
Each additional vector is plotted as an additional box.
A numeric value that determines the maximum amount that the
range whiskers extend from the boxes. 1.5
width A numeric vector specifying the widths of the boxes being plotted. NULL
If varwidth=TRUE, each box is drawn with a width proportional to the
square root of the number of observations represented by the box. If
varwidth varwidth=FALSE, boxes are plotted with the same width. FALSE
If notch=TRUE, a "notch" is drawn in the boxes. Notches are drawn at
notch +/-1.58 IQR/sqrt(n). FALSE
outline A logical value specifying whether outliers should be drawn. TRUE
A character vector specifying the group names used to label each box
names plot.
If plot=TRUE, the box plots are plotted. If plot=FALSE, boxplot returns
plot a list of statistics that could be used to draw a box plot. TRUE
A character vector specifying the color to use for the outline of each
border box plot. par("fg")
A character vector specifying the color to use for the background of
col each box plot. NULL
A character value indicating whether the axes should be plotted with a
log logarithmic scale. ""
list( boxweb =
0.8, stapleweb
= 0.5, outwex =
pars A list of additional graphical parameters passed to bxp. 0.5)
A logical value indicating whether the boxes should be drawn
horizontal horizontally (horizontal = TRUE) or vertically (horizontal=FALSE) FALSE
A logical value specifying whether the box plot should be added to an
existing chart (add=TRUE) or if a new chart should be drawn
add (add=FALSE). FALSE
1:n, where n is
A numeric vector specifying the locations at which each box plot the number of
at should be drawn. boxes

GRAPHICAL PARAMETERS
Parameter Description Default
Controls how text is justified in text, mtext, and title strings. Set adj=0
for left-justified text, adj=1 for right-justified text, and adj=0.5 for
adj centered text. 0.5
If ann=TRUE, then axis titles and overall titles are included with plots.
If ann=FALSE, these annotations are not included. Used by high-level
ann functions that call plot.default. TRUE
Within an interactive session, if ask=TRUE, then the user is asked for
ask input before a new chart is drawn. FALSE
bg The background color for the device region. transparent
bty The type of box to draw around a plot.
"o" for a box on all sides, "l" for the left and bottom only, "7" for top
and right only, "]" for right side, bottom and top only, "c" for left side,
bottom, and top only, "u" for left, right, and bottom only, "n" for no
box. o
cex This parameter controls the size of text and plotted points. 1
1 for normal size, 0.75 for 75% of normal size.
cex.axis Text magnification for axis notations, relative to cex. 1
cex.lab Text magnification for x and y labels, relative to cex. 1
cex.main Text magnification for main titles, relative to cex. 1.2
cex.sub Text magnification for subtitles, relative to cex. 1
cin Character size in inches. c(0.15, 0.2)
col Default plotting color. black
col.axis Color for axis annotation. black
col.lab Color for axis labels. black
col.main Color for main titles. black
col.sub Color for subtitles. black
cra Character size in pixels. c(10.8, 14.4)
A numeric value that specifies (in degrees) how individual characters
crt should be rotated. 0
csi Height of default size characters in inches. Same as par("cin")[2]. 0.2
c(0.02604167,
cxy Default character size in user coordinate units. 0.03875969)
din Device dimensions in inches. c(7,7)
err Degree of error reporting. Currently does nothing. 0
Name of font family used to draw text. Common values include "serif",
family "sans", "mono", and Hershey fonts.
fg Color for foreground of plots. black
fig A numeric vector that specifies the coordinates of the figure area. c(0, 1, 0, 1)
fin The figure area dimensions in inches. c(7, 7)
An integer that specifies what "font" to use in text (though it sounds
font like this really means "style"). 1
1 for normal, 2 for bold, 3 for italic, 4 for bold and italic, 5 to substitute
the Adobe Symbol font.
font.axis The "font" to be used for axis annotation. 1
font.lab The "font" to be used for x and y labels. 1
font.main The "font" to be used for the main plot titles. 2
font.sub The "font" to be used for plot subtitles. 1
A numeric vector with three elements (x, y, len) that specifies the way
that axes are annotated. X, y specify the approximate number of tick
lab marks on the x- and y-axes, and len specifies the label length. c(5, 5, 7)
las Specifies the style of axis labels.
0 for parallel to the axis, 1 for horizontal, 2 for perpendicular, 3 for
vertical. 0
lend Specifies the style of line ends. round
0 or "round" for round, 1 or "butt" for butt line caps, 2 or "square" for
square caps
lheight Specifies the height of a line when spacing multiple lines of text. 1
ljoin Specifies the style for joining lines. 1

0 or "round" for round, 1 or "mitre" for mitred, 2 or "bevel" for beveled.


lmitre Controls when mitred line joins are converted to beveled joins. 10
lty Line type. solid
0=blank, 1=solid, 2=dashed, 3=dotted, 4=dotdash, 5=longdash,
6=twodash.
lwd A positive number specifying line width. 1
A numeric vector c(bottom, left, top, right) that specifies margin size in c(1.02, 0.82,
mai inches. 0.82, 0.42)
A numeric vector c(bottom, left, top, right) that specifies margin size, in c(5.1, 4.1, 4.1,
mar number of lines. 2.1)
Specifies the expansion factor used for line size in mar. (The exact
mex relationship is mai=mar*mex*csi) 1
This parameter allows you to split a graphics device into a "matrix" of
subplots. This parameter is a numeric vector with two values: c(nrows,
ncols). Nrows represents a number of rows, and ncols represents a
number of columns. When more than one and column are specified, R
will split the device area into the specified number of rows and
mfcol columns. c(1, 1)
If a matrix of subplots is being drawn on a graphics device, you can
use mfg to specify the next plot to be drawn. Specified as c(row,
column, nrows, ncolumns). (When queried, this returns the location of
mfg the last figure plotted.) c(1, 1, 1, 1)
mfrow Identical to mfcol. c(1, 1)
A numeric vector with three values that controls the margin line for an
mgp axis title. Mgp[1] is used for the title; mgp[2:3] is used for the axis. c(3, 1, 0)
mkh The height of symbols when pch is an integer. 0.001
A logical value that indicates whether the plotting routine should
pretend that the graphics device has been freshly initialized (and is
new thus empty). Used to plot a figure on top of another one. >FALSE
A numeric vector c(bottom, left, top, right) that specifies the outer
oma margin in lines. c(0, 0, 0, 0)
A numeric vector c(bottom, left, top, right) that specifies the outer
margin as a fraction of the size of the whole device. (For example, a
value of 0 means the leftmost or top value, and a value of 0.5 means
omd dead center. c(0, 1, 0, 1)
A numeric vector c(bottom, left, top, right) that specifies the outer
omi margin in inches. c(0, 0, 0, 0)
Specifies the default point type. Symbols can be specified as numbers
pch or as a character. 1
19 for solid circle, 20 for bullet, 21 for filled circle, 22 for filled square,
23 for filled diamond, 24 for filled triangle point up, 25 for filled triangle
point down.
pin The dimensions of the current plot in inches. c(5.76, 5.16)
c(0.1171429,
0.9400000,
A vector that specifies the coordinates of the plot region as fractions 0.1457143,
plt of the figure region. 0.8828571)
ps An integer value specifying the point size of text (not symbols). 12
pty Specifies the type of plotting region. m
"s" for square, "m" to maximize the use of space.
smo Specifies how smooth circles and arcs should be. 1
srt Specifies the rotation of strings in degrees. (Only used by text.) 0
The length of tick marks. Specified as a fraction of the width or height
tck of the plotting region (whichever is smallest). NA
tcl The length of tick marks as a fraction of the height of a line of text. -0.5
A vector c(x1, x2, y1, y2) that specifies the extreme values of user
coordinates in the plotting region. (Note that these values are scaled
usr exponentially when a logarithmic scale is used.) c(0, 1, 0, 1)
Controls how tick marks are shown in the x-axis. Specified as a vector
c(x1, x2, n). When a linear scale is being used, specifies the minimum
(x1) and maximum (x2) tick mark locations and the number of tick
marks. When a logarithmic scale is being used, these parameters
mean something else: x1 is the lowest power of 10, x2 is the highest
power of 10, and n specifies the number of tick marks plotted for each
xaxp power of 10. c(0, 1, 5)
Controls the calculation method used to find axis intervals on the x-
axis. The regular method, xaxs="r", extends the data range by 4% on
each side and then tries to find pretty labels. The internal method,
xaxs="i", tries to find labels within the data range. (There are other
xaxs valid values, but they aren't currently implemented.) r
Specifies the x-axis type. Use xaxt="n" for no axis; any other value to
xaxt plot an axis. s
A logical value that specifies whether the scale of the x-axis is
xlog logarithmic. FALSE
Controls clipping. Use xpd=FALSE to clip to the plot region,
xpd=TRUE to clip to the figure region, and xpd=NA to clip to the
xpd device region. FALSE
yaxp Controls how tick marks are shown in the y-axis. c(0, 1, 5)
Specifies the calculation method used to find the axis intervals on the
yaxs y-axis. r
Specifies the y-axis type. Use yaxt="n" for no axis; any other value to
yaxt plot an axis. s
A logical value that specifies whether the scale of the y-axis is
ylog logarithmic. FALSE

POINTS
Argument Description Default
col Specifies the foreground color for the plotted points.
bg Specifies the background color of the plotted points.
pch Specifies the plotting character.
cex Specifies the size of the plotted points.
lwd Specifies the line width for the plotted points.

LINES
Argument Description Default
x, y Specifies the intersections between the line segments.
lty Specifies the line type.
lwd Specifies the line width.
col Specifies the line color.
lend Specifies the line end style.
ljoin Specifies the line join style.
lmitre Specifies the line mitre style.

CURVE
Argument Description Default
The expression to plot (written as a function of x) or the name of a
expr function plot.
from The lowest x value at which expr is evaluated. NULL
to The highest x value at which expr is evaluated. NULL
A positive integer value specifying the number of values at which to
n evaluate expr between the x limits (specified by xlim). 101
add A logical value indicating whether to add the curve to the current plot. FALSE
type Specifies the plot type. "l"
"p" for points, "l" for lines, "o" for overplotted points and lines, "b" for
points joined by lines, "c" for empty points joined by lines, "s" for stair
steps, "h" for histogram-like vertical lines, "n" for nothing.
ylab A character value specifying the label for the y-axis. ylab
log A logical value specifying whether to plot on a logarithmic scale. log
A numeric vector with two values specifying the lowest and highest x
xlim values to plot. NULL

TEXT
Argument Description Default
These arguments specify the coordinates at which the text labels will
x, y be drawn. y=NULL
A vector of character values specifying the text values that should be
labels drawn on the chart. seq_along(x)
A numeric vector with one or two values (each between 0 and 1). If
one value is used, it represents the horizontal adjustment. If two
values are used, the first represents the horizontal adjustment, and the
adj second represents the vertical adjustment. NULL
A numeric value that specifies where the text should be positioned.
pos Overrides values specified in adj. NULL
1 for below, 2 for the left, 3 for above, 4 for right.
A numeric value that specifies the offset of the labels in terms of
offset character widths. (Only valid when pos is specified.) 0.5
A character vector with two elements specifying the font to use for
labels. Vfont[1] specifies a Hershey font family; vfont[2] specifies a
vfont typeface within the family. NULL
cex Numeric value specifying the character expansion factor. 1
col Specifies the color of the plotted text. NULL
font Specifies the font to be used for the plotted text. NULL

ABLINE
Argument Description Default
a The intercept for the line. NULL
b The slope for the line. NULL
h A numeric vector of y values for horizontal lines. NULL
v A numeric vector of x values for vertical lines. NULL
reg Specifies an object with a coef method. NULL
A numeric vector with two elements specifying the intercept and
coef slope. NULL
A logical value specifying whether to "untransform" the line; if one or
both axes are in logarithmic coordinates and untf=TRUE, then the line
is shown in original coordinates. Otherwise, the line is plotted in
untf transformed coordinates. NULL

GRID
Argument Description Default
nx
ny
col
lty
lwd
equilogs

POLYGON
Argument Description Default
x, y Specifies the vertices of the polygon.
density
angle
border
col
lty

SEGMENTS
Argument Description Default
x0
y0
x1
y1
col
lty
lwd

LEGEND
Argument Description Default
x, y The coordinates at which the legend will be positioned. y=NULL
legend A character vector to appear in the legend.
A character vector specifying a color associated with each legend
label. If specified, boxes filled with these colors are shown next to the
fill labels. NULL
col The color of lines appearing in the legend. par("col")
lty The line type for lines appearing in the legend.
lwd The line width for lines appearing in the legend.

pch A vector of values specifying point characters appearing in the legend.


angle Angle of shading lines. 45
density Density of shading lines. NULL
bty Box type for box drawn around the legend. "o"
bg Background color for the legend box. par("bg")
box.lwd Line width for the legend box. par("lwd")
box.lty Line type for the legend box. par("lty")
box.col Line color for the legend box. par("fg")
Background color for points shown in the legend box (if pch is
pt.bg specified). NA
cex Character expansion value for legend relative to par("cex"). 1
pt.cex Expansion factor for points in the legend. cex
pt.lwd Line width for points in the legend. lwd
xjust Specifies how the legend should be justified relative to the x location. 0
0 for left justification, 0.5 to center, 1 for right justification.
yjust Specifies how the legend should be justified relative to the y location. 1
x.intersp Character "interspacing factor" for horizontal spacing. 1
y.intersp Character "interspacing factor" for vertical spacing. 1
adj String adjustment for legend text. c(0, 0.5)
text.width Width of legend text in user coordinates. NULL
text.col Color used for legend text. par("col")
do.lines &&
merge If merge=TRUE, merge points and lines but not filled boxes. has.pch
trace Logical value. If trace=TRUE, shows how legend calculates stuff. FALSE
Logical value. If plot=FALSE, calculations are returned but no legend
plot is drawn. TRUE
ncol Specifies the number of columns to draw in the legend. 1
Specifies whether the legend should be laid out vertically
horiz (horiz=FALSE) or horizontally (horiz=TRUE). FALSE
title A character value to be placed at the top of the legend box. NULL
Inset distance from the margins. Specified as a draction of the plot
inset region. 0
xpd Controls clipping while the legend is being drawn.
title.col Color for the title. text.col

AXIS
Argument Description Default
side An integer value specifying where to draw the axis.
1 for below, 1 for left, 3 for above, 4 for right.
A numeric vector specifying points at which tick marks are drawn. (If
not specified, uses the same method as axTicks to compute "pretty"
at tick mark locations.) NULL
Either a logical value or a vector. If logical, spcifies whether numeric
annotations are added at tick marks. If a vector is specified, each
labels value specifies the label to place at each tick mark. TRUE
tick A logical value specifying if tick values and an axis will be drawn. TRUE
The number of lines into the margin at which the axis will be drawn.
(Can be used to add space between plotted values and the axis.) Use
line line=NA for no space. NA
The coordinate at which the axis will be drawn. (If not NA, overrides
pos line.) NA
A logical value specifying whether the axis should be drawn in the
outer margin. Use outer=FALSE to draw the axis in the standard
outer margin. FALSE
font Font for axis text. NA
lty Line type for axis line and tick marks. "solid"
lwd Line width for axis line. 1
twd.ticks Line width for tick marks. lwd.ticks
col Color for axis line. col
col.ticks Color for tick marks. col.ticks
hadj Adjustment for all labels parallel to the reading direction. NA
padj Adjustment for all labels perpendicular to the reading direction. NA

You might also like