R syntax collection — 14-11-2010 [FB] • VARIABLES, ARRAYS, MATRICES, DATA FRAMES, LISTS x = 0:10 # integer step size, yields numerical vector xt=t(x) # converts x into a matrix of 1 x 11 xtt=t(t(x)) # converts x into a matrix of 11 x 1 x = (0:100)/100 # computation; allows arbitrary step size y = c(1, 3, 7, 11) # c() = concatenate x = seq(-pi,pi,length=100) x = seq(0, 6,by=.1) a = matrix(0, 4, 7) # zeros; 4 rows of 7 columns y = array(1,length(x)) # ones, as many as x'es z = array(0, c(3,4,2)) # 3D array q = rbind(x,x,x) # 3 rows of vector x (cbind for columns) 1L means: ...Introduced the suffix L for integer literals to create integer rather than numeric values, e.g., 100L, 0x10L, 1e2L. xdec = 0xFFFF # conversion hex to dec (ex. yields 65535) h=toupper(as.hexmode(65535)) # yields "FFFF" format.hexmode(44100) # printing of hexadecimal numbers (ex. yields "ac44") format.hexmode(0x1000-0xFF) # hexadecimal computations (ex. yields "f01") y[2,3] # one element of 2D matrix y[,2] # column 2 y[,3:5] # colums 3 .. 5 y[2,] # row 2 y[3:5,] # rows 3 .. 5 y[,2:5] or y[,c(2,3,4,5)] # columns 2–5 which(x==a) # returns indices of x where x==a # find transitions: y=which(x[2:100]!=x[1:99]) rev(x) # reverses vector x (last ... first) sort(x, decreasing=F) # sorts vector x in increasing (or decreasing if T) order mm[order(mm$a),] # sort whole matrix on basis of one column a=staff$salary; f=staff$function ## object component extraction l=mywave@left; r=mywave@right; sf=mywave@samp.rate ## object slot extraction # interpolation functions x=1:5; y=c(1, 3, 5, 4, 2); z=approx(x,y,n=17) # linear interpolation z=spline(x,y,n=21); plot(x,y); lines(z,col='blue') # smoothed interpolation # names for matrix rows and columns x=cbind((0:10),(0:10)^2) # matrix w. 2 colums dimnames(x) = list(0:10,c("value","square")) # labels for rows & columns resp. rep(1:4, 2) # yields 1 2 3 4 1 2 3 4 rep(1:4, each = 2) # yields 1 1 2 2 3 3 4 4 double(length = n) # vector of double-precision floats as.double(x, ...) # coerces x as '' '' '' is.double(x) # tests x on being '' '' '' integer(length = n) # vector of integers (4-byte?) as.integer(x, ...) is.integer(x) is.integer(4L) # is TRUE (L suffix) storage.mode(x)="integer" • BUILT-IN OPERATORS & FUNCTIONS The following unary and binary operators are defined. They are listed in precedence groups, from highest to lowest. [ [[ indexing :: ::: access variables in a name space $ @ component / slot extraction ^ exponentiation (right to left) - + unary minus and plus : sequence operator %any% special operators * / multiply, divide + (binary) add, subtract < > <= >= == != ordering and comparison ! negation & && and | || or ~ as in formulae -> ->> rightwards assignment = assignment (right to left) <- <<assignment (right to left) ? help (unary and binary) ceiling(x) floor(x) trunc(x) round(x, digits = 0) signif(x, digits = 6) exp(x) # exponentiate (e^x) log(x) # natural logarithms (base e) log10(x) # common logarithms (base 10) log2(x) #binary logarithms (base 2) logb(x, base) # log w. arbitrary base sqrt(x) # square roots cos(x) cosine sin(x) sine tan(x) tangent acos(x) arccosine asin(x) arcsine atan(x) arctangent atan2(y, x) besselJ(x, besselY(x, besselI(x, besselK(x, nu) nu) nu, expon.scaled = FALSE) nu, expon.scaled = FALSE) (1:3) * (1:6) # vector multiplication; yields: [1] 1 4 9 4 10 18 (1:3) %*% t(1:6) # matrix multip; yields: [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 2 3 4 5 6 [2,] 2 4 6 8 10 12 [3,] 3 6 9 12 15 18 diff(y, lag = 1, differences = 1) # differentiate vector (or columns of matrix) (length of diff(y) < length(y)! cumsum(y) # integral, must be normalized, length cumsum(y) = length(y). lapply(mylist, sum) # apply function to list lapply(mylist, `^`,2) # apply operator to list • LOGIC ! x # NOT (negation) operator 2 x & y x && y x | y x || y xor(x, y) isTRUE(x) # # # # # # element-wise AND operator (returns equally long vector) first element AND operator (returns one element) element-wise OR operator (returns equally long vector) first-element OR operator (returns one element) elementwise exclusive OR operator not operator (returns one element) is.na # true if data is missing (NA = not available) z=y[!is.nan(y)] # z = all y that is not NaN (not a number) # logic to numeric lo=x/2==fix(x/2) # logic; row of trues and falses nu=1*(x/2==fix(x/2)) # the same numeric; ones and zeros # lists Lst = list(name="Fred", wife="Mary", no.children=3, child.ages=c(4,7,9)) list.ABC = c(list.A, list.B, list.C) mylist[1] yields a list (component) mylist[[1]] yields this component's contents (e.g. numeric) # data frames accountants = data.frame(home=statef, loot=incomes, shot=incomef) demo = accountants$statef # data to frame days=(c("ma","di","wo","do","vr","za","zo")) times=(c(11,12,1,2,3,4,5)) measurements=(c(50,40,30,60,40,30,30)) experiment=as.data.frame(cbind(days, times, measurements)) data.frame(v1,v2) # make a data frame from vectors v1 and v2 merge(df1,df2) # merge data frames # EDIT data like a spreadsheet xnew = edit(xold) • STRINGS grep(pattern, x, ignore.case = FALSE, extended = TRUE, perl = FALSE, value = FALSE, fixed = FALSE, useBytes = FALSE) help(regex) # help for regular expressions, as used in "grep" \’ single quote \" double quote \n newline \r carriage return \t tab character \b backspace \a bell \f form feed \v vertical tab \\ backslash itself \nnn character with given octal code – one, two or three digits 0 ... 8. \xnn character with given hex code – one or two hex digits (0 ... F). c("alpha ","beta ", "gamma") # concatenates the arguments cat("alpha ","beta ", "gamma") # prints the arguments paste(strname, ":", 15, "x", 20, "cm") # is string concatenation substring(strname, start, stop) # start and stop are character numbers strsplit(strname, " ") # split on character "space'; becomes a LIST! strsplit("abcd",split="") # Split into separate characters paste(naam,x) # coerces num vars to strings, conatenates them (for labels etc.) paste("ab","c","d",sep="") # Join together paste(c("a","b","c"),collapse="") # Join vector elements as.raw(127) # convert numeric var to raw byte(s) (e.g. 127 -> 7f) rawToChar(as.raw(65)) # convert decimal number to ASCII character (65 -> "A") 3 as.numeric(charToRaw("a")) # convert ASCII to number ("a" -> 97) • MANUAL I/O print(cat(x,y,z, file="", sep=' , ')) # standard output, i.e. screen cat("\n x = ",x,"\n") # common screen printing routine sprintf(fmt, variable, variable) # print with formatting string "fmt" sprintf("%s is %f feet tall\n", "Sven", 7.1) data.entry(x,y) # sort of spreadsheet to enter data manually SPECIAL CHARACTERS FOR FORMAT STRINGS After a % sign: d, i, x, X Integer value, x and X being hexadecimal (using the same case for a-f as the code). Numeric variables with exactly integer values will be coerced to integer. f Double precision value, in decimal notation of the form "[-]mmm.ddd". The number of decimal places is specified by the precision: the default is 6; a precision of 0 suppresses the decimal point. e, E Double precision value, in decimal notation of the form [-]m.ddde[+-]xx or [-]m.dddE[+-]xx. g, G Double precision value, in %e or %E format if the exponent is less than -4 or greater than or equal to the precision, and %f format otherwise. s Character string. % Literal % (none of the formatting characters given below are permitted in this case). txt = readline("remarks = ") # alpha keyboard input with prompt x = as.double(readline("x = ")) # numeric keyboard input with prompt z=scan() # scan reads data up to empty line menu(choices, graphics = FALSE, title = "") # menu on command console switch(menu(c("Choice 1", "Choice 2","Choice 3"),graphics=TRUE) + 1, + cat("Nothing done\n"), cat("first item chosen"), cat("second item chosen"),cat("third item chosen")) # "+1" is to make 0 =cancel possible • FILE I/O inname = file.choose() # file read selector outname = file.choose(new=T) # file write selector # this becomes a "data frame" of all columns of the file "inname.txt" a = read.table("inname.txt") y <- read.table(file=pipe("pbpaste"),header=FALSE) # read from clipboard mydata=read.delim(inname, header = FALSE, sep = "\t", quote="\"", dec=".", fill = TRUE) b = scan(file = inname, nmax = -1) # becomes all numbers in one row readChar(inname, nchars) cat("\n x= ", x, file="test.txt") # print to file write(x, "", sep = "\t") # file "" means to the screen write(x,file="x.txt") write(t(x)) # transpose to get columns write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ", eol = "\n", na = "NA", dec = ".", row.names = TRUE, col.names = TRUE, qmethod = c("escape", "double")) writeChar(m, outname, nchars = nchar(m, type="chars"), eos = "") zz <- file(inname, "rb") # open binaire file als stream (rb = Read Binary) # read 1-byte, unsigned, offset binary integers (eg Hameg 507) bulk=readBin(zz, "int", n=256000, size=1,signed=FALSE)-127 # read 2-byte integers (little-endian; eg raw sound from Amadeus) bulk=readBin(zz, "int", n=441000, size=2, signed=TRUE) a=scan(pipe("pbpaste",open="r"), what="character") # read OS X clipboard 4 # write to OS X clipboard: x="my data"; y=pipe("pbcopy", open="w"); write(x,y); close(y) • PLOTTING quartz() # open Mac graphics device(used to create several parallel windows) quartz(width=12, height=10) dev.set(n) # make n-th device active dev.copy(which = n) # copy contents from active device (window) to device n. dev.off(which = n) # close window n (default: current) pdf(file.choose(new=T), width=7,height=11); plot(x,y); dev.off(which=dev.cur()) # save plot als A4-tje "pdf" # shorter with dev.copy after plot. Enter file name, else named "Rplot.pdf" quartz(width=7, height=7); plot(1:11); dev.copy2pdf(file="myplot.pdf") devSVG(file = "drawingname.svg", width = 10, height = 8,bg = "white", fg = "black", onefile=TRUE, xmlHeader=TRUE) split.screen(c(2,1)) #splits screen in 2 rows (of 1 figure) split.screen(c(1,2),screen=2) # splits lower screen in 2 columns screen(n=1) # select and clear screen(1, FALSE) # select without clearing erase.screen(n=2)) mat=matrix(data=c(1,3,2,4),nrow=2,ncol=2) layout(mat, w=c(2,1),h=c(1,2)) par(mfrow=(c(2,3))) # raster 2 r 3 col: 1 2 3 4 5 6 par(mfcol=(c(2,3))) # same raster, filled column-wise par(pin=c(4, 3)) # plot width 4, height 3 inch par(pin=c(10,8)) # plot size of 10" x 8" par(pin=c(par("pin")[1], 1)) # plot width as standard, height 1 inch plot(x,y,xlim=range(x),xlab= NA, ylab= NA, ylim=c(ymin, ymax), pch=16, cex=2, col='red') plot(x,y, log="xy") # log-log plot plot(x, y, log='x', xaxp=c(1,10000,3)) # xaxp: tickmarks (3 = 1-2-5 series) plot(x,y); abline(lm(y~x), lty=3) # plot points and regression line y on x title(main = title, sub = 'subtitle', xlab= 'X value' ,ylab= 'Y value', line = NA, outer = FALSE) legend(xmax*.8,ymax*.8, leg) text(1,8,txt, cex=2) text(2,-.5, cex=1.2, "oblique up", srt=45) text(2,-.5,"text over\ntwo lines", cex=1.2) text(x,y,txt, cex=1, adj = c(0, 0)) # bottom left justified mtext("text side 4", side=4, line=1, cex=1.6) # margin text lines(spline(x,y, n=201), lty=1, lwd=3,col='grey') lines(x,y,"h") # h = histogram (or spectrum) -like vertical lines points(x, y = NULL, type = "p", pch = par("pch"), col = par("col"), bg = NA, cex = 1, ...) pch="." small dot (decimal point) pch=19: solid circle, see below 5 symbols(x,y,circles=abs(y),inch=0.5) # circle radii, also squares, stars etc. plot(x,y,pch=19,cex=z) # dot size from variable barplot(y, width = 1, space = .5, names.arg = NULL, legend.text = NULL, beside = FALSE, horiz = FALSE, density = NULL, angle = 45, col = "blue", border = par("fg"), main = NULL, sub = NULL, xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, xpd = TRUE, log = "", axes = TRUE, axisnames = TRUE, cex.axis = par("cex.axis"), cex.names = par("cex.axis"), inside = TRUE, plot = TRUE, axis.lty = 0, offset = 0, add = FALSE) # plot a matrix or data frame having one x column, then several y columns: matplot(z[,1],z[,2:5],type='l') # plot columns of a matrix against the first one matplot(z[,1],z[,2:ncol(z)],type='l' # general: all other columns against #1 # special x-as axis(1,at=c(-pi,-pi/2,0,pi/2,pi), labels=expression(-pi, -pi/2, 0, pi/2, pi)) # dual-Y plot y1 & y2 versus x plot(x,y1, pch=19, col=1, ylim=ylims) par(new=TRUE) plot(x,y2, axes=FALSE, xlab="", ylab="", pch=19, col=2) axis(4) # formulas as x and y labels plot(1:10,1:10, ylab=expression(r^2), xlab=expression(x[i]),type="n") # open platform-independent (Mac <--> Windows) graphics window pigraph <- function(w,h) if(.Platform$OS.type == "windows") windows(w=w, h=h) else quartz(w=w, h=h) • OBJECTS rect(xleft, ybottom, xright, ytop, density = 1, angle = 45, col = "red", border = NULL, lty = NULL, lwd = par("lwd"), xpd = NULL, ...) # circle (cex = size; for filled circle pch=19) points(x, y ,type = "p", pch = 21, col = "blue", cex=20) polygon(x, y, density = NULL, angle = 45, border = NULL, col = NA, lty = NULL, xpd = NULL, ...) segments(x0, y0, x1, y1, col = par("fg"), lty = par("lty"), lwd = par("lwd")) abline(a, b) # intercept and slope respectively abline(h=1) # horizontal line abline(v=1) # vertical line arrows(x0, y0, x1, y1, length = 0.25, angle = 30, code = 2, col = par("fg"), lty = NULL, lwd = par("lwd"), xpd = NULL) lty= The line type. (0=blank, 1=solid, 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash) or "blank", 6 "solid", "dashed", "dotted", "dotdash", "longdash", or "twodash", where "blank" uses ‘invisible lines’ (i.e., doesn’t draw them). # plotmath examples: text(x, y, expression(x %->% z)) # right arrow text(x, y, expression(bar(x) == hat(beta) + frac(x, y))) text(1, 5, "perpendicular", adj=0); text(4, 5, expression(symbol("\136"))) text(c(5, 5.5, 6), c(5, 5, 5), expression(bar(u), bar(v), bar(w))) text(x, y, quote(symbol("\300")),cex=5) # large aleph COLOURS: col A specification for the default plotting color. col.axis The color to be used for axis annotation. col.lab The color to be used for x and y labels. col.main The color to be used for plot main titles. col.sub The color to be used for plot sub-titles. colors() prints all builtin colours col = "orange" col = "#RRGGBB" # Where RR, GG, BB consist of two hex digits (00 to FF). image(x, y, z, zlim, xlim, ylim, col = heat.colors(12), add = FALSE, xaxs = "i", yaxs = "i", xlab, ylab, breaks, oldstyle = FALSE, ...) filled.contour(x = seq(0, 1, len = nrow(z)), y = seq(0, 1, len = ncol(z)), z, xlim = range(x, finite=TRUE), ylim = range(y, finite=TRUE), zlim = range(z, finite=TRUE), levels = pretty(zlim, nlevels), nlevels = 20,color.palette = cm.colors, col = color.palette(length(levels) - 1), plot.title, plot.axes, key.title, key.axes,asp = NA, xaxs = "i", yaxs = "i", las = 1,axes = TRUE, frame.plot = axes, ...) colorRampPalette(c("red", "yellow", "white")) • GRID & TRELLIS GRAPHICS trellis.device(w=5,h=9) trellis.par.set(theme=col.whitebg()) xyplot(y ~ x | factor1*factor2, data = mydata) # trellis y/x with factors 1 & 2 • 3D PLOTTING [see also 'packages'] palette(terrain.colors(8)) persp(x,y,z,d=100,theta=30,phi=45, shade=.5) meshgrid <- function(a,b) {list(x=outer(b*0,a,FUN="+"),y=outer(b,a*0,FUN="+"))} # Interactive 3D plotting require(rgl) # needs rgl package open3d() par3d(windowRect=c(64,64,640,640)) plot3d(x, y, z, col=rainbow(1000)) • FUNCTIONS fname = function(arg_1, arg_2, ...) {expression, expression, ...} # call: z= fname(expr_1, expr_2, ...) # simple example sinc = function(x) {sin(x)/x} rectif=function(x) abs(sin(x)) 7 # multiple output difsum=function(x,y) {a=x+y; b=x-y; return(c(a,b))} moments = function(x) { mw = mean(x); s = sd(x); k=cum3(x) return(c(Mean=mw, StDev=s, Skew=k))} # recursive fact = function(n) {if (identical(1,n)) 1 else n*fact(n-1)} # more elaborate function with conditionals harmean <- function(v) { if (!is.numeric(v)) { print("Argument must be numeric"); return(NULL) } else if (any(v <= 0)) { print("All elements must be positive"); return(NULL) } else return(exp(sum(log(v))/length(v))) } # this function changes global variables! Use of the "<<-" assignment tst = function(x,y) { p <<- 1/(1/x+1/y) s <<- x+y } • STATISTICS factorial(n) # i.e. n! choose(n, k) # combinations of k out of n permute = function(n,k) {choose(n,k)*factorial(k)} combine = function(n,k) {choose(n,k)} sample(x, size, replace = FALSE, prob = NULL) # example below population=1:100; sample(population,10) sum(x) # sum of elements of vector x mean(x) # the mean of the elements of x weighted.mean(x,w) # w is a vector with weights, same length as x hist(y,n) # y=sample vector; n=number of classes hist(y,breaks=(0:20)/20) # 20 bars in 0..1 median(x) # the median of the elements of x var(x) # the variance of the elements of x sd(x) # the standard deviation of the elements of x quantile(x) # yields 0, 25, 50, 75 and 100% quantile(x, 0:10/10) # yields 0, 10, 20 ... 100% • PROGRAM FLOW STRUCTURES for(i in 1:length(x)) {expression; expression; ...} if (x > 0) {y = sqrt(x); z=101} if (x > 0) y = sqrt(x) else y = -sqrt(-x) y = if (x > 0) sqrt(x) else -sqrt(-x) # shorthand of last statement while(x<10) {print(x); x=x+1} repeat {print("hallo"); if(x==10) break; x=x+1} next switch(sign(D)+2,print("negative"),print("zero"),print("positive")) # mouse control loc=locator(n=1) # yields n pairs of coordinates as list (loc$x en loc$y) pnt=identify(x,y,n=1,labels = rep('X',length(butx)), tolerance=1) 8 • SYSTEM CALLS & INFORMATION .Machine info like eps, largest & smallest number, exponent etc. system('ls -l') unix command in R console • PACKAGES stats:::filter(....) # invoke function from a specific package • rgl & misc3d (3D open-gl plotting packages) rgl.points(x, y, z, size=1) rgl.open() contour3d(function(x,y,z) {2*x^2+y^2+.5*z^2},4,x,x,x) rgl.viewpoint( theta = 45, phi = 30, fov = 60, zoom = 1, interactive = TRUE) rgl.bringtotop() • plotrix axis.break(axis=1,breakpos=NULL,bgcol="white",breakcol="black", style="slash",brw=0.02) l <- list(runif(10)*10,1:10,c(1,1,1,1,4,8)) multhist(l) 9 • PAR par(..., no.readonly = FALSE) par() (no arguments) or par(no.readonly=TRUE) get all the graphical parameters LIST OF PARAMETERS adj text strings justification. 0 = left-justified, 0.5 centered 1 rightjustified text. ann If FALSE, high-level plotting functions do not annotate the The default is to do annotation. ask If TRUE, the user is asked for input, before a new figure is drawn. bg The color to be used for the background of plots. A description of how colors are specified is given below. Note that some graphics functions such as plot.default and points have an argument of this name with a different meaning. bty type of box around plots. If bty is one of "o", "l", "7", "c", "u", or "]" the resulting box resembles the corresponding upper case letter. A value of "n" suppresses the box. cex plotting scale of text and symbols relative to the default. cex.axis The magnification to be used for axis annotation relative to the current setting of cex. cex.lab The magnification to be used for x and y labels relative to the current setting of cex. cex.main The magnification to be used for main titles relative to the current setting of cex. cex.sub The magnification to be used for sub-titles relative to the current setting of cex. col A specification for the default plotting color. A description of how colors are specified is given below. col.axis The color to be used for axis annotation. col.lab The color to be used for x and y labels. col.main The color to be used for plot main titles. col.sub The color to be used for plot sub-titles. crt single character rotation in deg. (multiples of ). Compare with srt which does string rotation. family The name of a font family for drawing text. The maximum allowed length is 49 bytes. The default value is "" which means that the default device fonts will be used. Standard values are "serif", "sans", "mono", and "symbol" and the Hershey font families are also available. fg foreground color of plots. When called from par() this also sets parameter col to the same value. fig A numerical vector of the form c(x1, x2, y1, y2) which gives the (NDC) coordinates of the figure region in the display region of the device. If you set this, you start a new plot, so to add to an existing plot use new=TRUE as well. fin The figure region dimensions, (width,height), in inches. If you set this, you start a new plot. font Specifies which font to use for text. If possible, device drivers arrange so that 1 corresponds to plain text, 2 to bold face, 3 to italic and 4 to bold italic. Also, font 5 is expected to be the symbol font, in Adobe symbol encoding. On some devices font families can be selected by family to choose different sets of 5 fonts. font.axis The font to be used for axis annotation. font.lab The font to be used for x and y labels. font.main The font to be used for plot main titles. font.sub The font to be used for plot sub-titles. lab Num. vector of the form c(x, y, len) which modifies the default way that axes are annotated. X and y give the (approx) number of tickmarks on the x and y axes and len specifies the label length. The default is c(5, 5, 7). (affects xaxp and yaxp only. len is unimplemented in R. las numeric in {0,1,2,3}; the style of axis labels. 10 0: always parallel to the axis [default], 1: always horizontal, 2: always perpendicular to the axis, 3: always vertical. lend Line end style. Integer or string: 0 and "round" mean rounded line caps; 1 and "butt" mean butt line caps; 2 and "square" mean square line caps. lheight The line height multiplier. The height of a line of text (used to vertically space multi-line text) is found by multiplying the current font size both by the current character expansion and by the line height multiplier. Default value is 1. ljoin The line join style. Integer or string: 0 and "round" mean rounded line joins; 1 and "mitre" mean mitred line joins; 2 and "bevel" mean bevelled line joins. lmitre The line mitre limit. This controls when mitred line joins are automatically converted into bevelled line joins. The value must be larger than 1 and the default is 10. Not all devices will honour this setting. lty The line type. Integer (0=blank, 1=solid, 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash) or character strings "blank", "solid", "dashed", "dotted", "dotdash", "longdash", or "twodash", where "blank" uses ‘invisible lines’ (i.e., doesn't draw them). Alternatively, a string of up to 8 characters (from c(1:9, "A":"F")) may be given, giving the length of line segments which are alternatively drawn and skipped lwd The line width, a positive number, defaulting to 1. The interpretation is device-specific (some devices do not implement line widths less than one). mai A numerical vector of the form c(bottom, left, top, right) which gives the margin size specified in inches. mar A numerical vector of the form c(bottom, left, top, right) which gives the number of lines of margin to be specified on the four sides of the plot. The default is c(5, 4, 4, 2) + 0.1. mex Character size expansion factor which is used to describe coordinates in the margins of plots. Note that this does not change the font size, rather specifies the size of font used to convert between mar and mai, and between oma and omi. mfcol, mfrow A vector of the form c(nr, nc). Subsequent figures will be drawn in an nr-by-nc array on the device by columns (mfcol), or rows (mfrow), respectively. In a layout with exactly two rows and columns the base value of "cex" is reduced by a factor of 0.83: if there are three or more of either rows or columns, the reduction factor is 0.66. Consider the alternatives, layout and split.screen. mfg A numerical vector of the form c(i, j) where i and j indicate which figure in an array of figures is to be drawn next (if setting) or is being drawn (if enquiring). The array must already have been set by mfcol or mfrow. mgp The margin line (in mex units) for the axis title, axis labels and axis line. The default is c(3, 1, 0). new logical, defaulting to FALSE. If set to TRUE, the next high-level plotting command (actually plot.new) should not clean the frame before drawing “as if it was on a new device”. oma A vector of the form c(bottom, left, top, right) giving the size of the outer margins in lines of text. omd A vector of the form c(x1, x2, y1, y2) giving the outer margin region in NDC (= normalized device coordinates), i.e., as fraction (in [0,1]) of the device region. omi A vector of the form c(bottom, left, top, right) giving the size of the outer margins in inches. pch Either an integer specifying a symbol or a single character to be used as the default in plotting points. See points for possible values and their interpretation. pin The current plot dimensions, (width,height), in inches. plt A vector of the form c(x1, x2, y1, y2) giving the coordinates of the plot region as fractions of the current figure region. ps int. point size of text (but not symbols). NB: device-specific. pty A character specifying the type of plot region to be used; "s" generates a square plotting region and "m" generates the maximal plotting region. 11 srt tck tcl tmag usr xaxp xaxs xaxt xlog xpd yaxp yaxs yaxt ylog The string rotation in degrees. See the comment about crt. Length of tick marks as a fraction of the smaller of the width or height of the plotting region. If tck >= 0.5 it is interpreted as a fraction of the relevant side, so if tck = 1 grid lines are drawn Length of tick marks as a fraction of the height of a line of text. The default value is -0.5; setting tcl = NA sets tck = -0.. Enlargement of text of the main title relative to the other annotating text of the plot. Defaults to 1.2. A vector of the form c(x1, x2, y1, y2) giving the extremes of the user coordinates of the plotting region. When a logarithmic scale is in use (i.e., par("xlog") is true, see below), then the x-limits will be 10 ^ par("usr")[1:2]. Similarly for the y-axis. A vector of the form c(x1, x2, n) giving the coordinates of the extreme tick marks and the number of intervals between tick-marks when par("xlog") is false. Otherwise, when log coordinates are active, the three values have a different meaning: For a small range, n is negative, and the ticks are as in the linear case, otherwise, n is in 1:3, specifying a case number, and x1 and x2 are the lowest and highest power of 10 inside the user coordinates, 10 ^ par("usr")[1:2]. (The "usr" coordinates are log10transformed here!) n=1 will produce tick marks at 10^j for integer j, n=2 gives marks k 10^j with k in {1, 5}, n=3 gives marks k 10^j with k in {1, 2, 5}. See axTicks() for a pure R implementation of this. The style of axis interval calculation to be used for the x-axis. Values are "r", "i". Style "r" (regular) first extends the data range by 4 percent and then finds an axis with pretty labels that fits within the range. Style "i" (internal) just finds an axis with pretty labels that fits within the original data range. X axis type. Specifying "n" suppresses plotting of the axis. The standard value is "s". Any value other than "n" implies plotting. If TRUE, a logarithmic scale is in use (e.g., after plot(*, log = "x")). For a new device, it defaults to FALSE, i.e., linear scale. A logical value or NA. If FALSE, all plotting is clipped to the plot region, if TRUE, all plotting is clipped to the figure region, and if NA, all plotting is clipped to the device region. A vector of the form c(y1, y2, n) giving the coordinates of the extreme tick marks and the number of intervals between tick-marks unless for log coordinates, see xaxp above. Axis interval calculation for the y-axis. See xaxs above. A character which specifies the y axis type. Specifying "n" suppresses plotting. A logical value; see xlog above. 12