R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("gplots-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('gplots') Loading required package: gdata Loading required package: gtools Loading required package: gtools Attaching package: 'gplots' The following object(s) are masked from package:stats : lowess > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "balloonplot" > > ### * balloonplot > > flush(stderr()); flush(stdout()) > > ### Name: balloonplot > ### Title: Plot a graphical matrix where each cell contains a dot whose > ### size reflects the relative magnitude of the corresponding component. > ### Aliases: balloonplot balloonplot.default balloonplot.table > ### Keywords: dplot hplot > > ### ** Examples > > ## Don't show: > set.seed(12425421) > ## End Don't show > > # Create an Example Data Frame Containing Car x Color data > carnames <- c("bmw","renault","mercedes","seat") > carcolors <- c("red","white","silver","green") > datavals <- round(rnorm(16, mean=100, sd=60),1) > data <- data.frame(Car=rep(carnames,4), + Color=rep(carcolors, c(4,4,4,4) ), + Value=datavals ) > # show the data > data Car Color Value 1 bmw red 138.9 2 renault red 150.7 3 mercedes red 111.5 4 seat red 73.8 5 bmw white 24.7 6 renault white 245.9 7 mercedes white 85.7 8 seat white 18.2 9 bmw silver -65.7 10 renault silver -16.6 11 mercedes silver 180.6 12 seat silver 76.1 13 bmw green 121.4 14 renault green 171.2 15 mercedes green 183.1 16 seat green 95.3 > > # generate balloon plot with default scaling > balloonplot( data$Car, data$Color, data$Value) Warning in balloonplot.default(data$Car, data$Color, data$Value) : z value(s) below zero detected. These will have zero size. > > # show margin label rotation & space expansion, using some long labels > levels(data$Car) <- c("BMW: High End, German","Renault: Medium End, French", + "Mercedes: High End, German", "Seat: Imaginary, Unknown Producer") > > # generate balloon plot with default scaling > balloonplot( data$Car, data$Color, data$Value, colmar=3, colsrt=90) Warning in balloonplot.default(data$Car, data$Color, data$Value, colmar = 3, : z value(s) below zero detected. These will have zero size. > > # Create an example using table > xnames <- sample( letters[1:3], 50, replace=2) > ynames <- sample( 1:5, 50, replace=2) > > tab <- table(xnames, ynames) > > balloonplot(tab) > > > > > cleanEx(); ..nameEx <- "bandplot" > > ### * bandplot > > flush(stderr()); flush(stdout()) > > ### Name: bandplot > ### Title: Plot x-y Points with Locally Smoothed Mean and Standard > ### Deviation > ### Aliases: bandplot > ### Keywords: dplot > > ### ** Examples > > > # fixed mean, changing variance > x <- 1:1000 > y <- rnorm(1000, mean=1, sd=1 + x/1000 ) > bandplot(x,y) > > # fixed varance, changing mean > x <- 1:1000 > y <- rnorm(1000, mean=x/1000, sd=1) > bandplot(x,y) > > # > # changing mean and variance > # > x <- abs(rnorm(500)) > y <- rnorm(500, mean=2*x, sd=2+2*x) > > # the changing mean and dispersion are hard to see whith the points alone: > plot(x,y ) > > # regression picks up the mean trend, but not the change in variance > reg <- lm(y~x) > summary(reg) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -16.55270 -2.23149 0.02077 2.27932 16.59931 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.07014 0.29689 -0.236 0.813 x 2.16529 0.28648 7.558 1.98e-13 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 3.972 on 498 degrees of freedom Multiple R-Squared: 0.1029, Adjusted R-squared: 0.1011 F-statistic: 57.13 on 1 and 498 DF, p-value: 1.976e-13 > > # using bandplot on the original data helps to show the mean and > # variance trend > bandplot(x,y) > > # using bandplot on the residuals helps to see that regression removes > # the mean trend but leaves the trend in variability > bandplot(predict(reg),resid(reg)) > > > > > cleanEx(); ..nameEx <- "barplot2" > > ### * barplot2 > > flush(stderr()); flush(stdout()) > > ### Name: barplot2 > ### Title: Enhanced Bar Plots > ### Aliases: barplot2 barplot2.default > ### Keywords: hplot > > ### ** Examples > > tN <- table(Ni <- rpois(100, lambda = 5)) > r <- barplot2(tN, col = 'gray') > > #- type = "h" plotting *is* `bar'plot > lines(r, tN, type = 'h', col = 'red', lwd = 2) > > barplot2(tN, space = 1.5, axisnames = FALSE, + sub = "barplot2(..., space = 1.5, axisnames = FALSE)") > > data(VADeaths, package = "base") Warning in data(VADeaths, package = "base") : datasets have been moved from package 'base' to package 'datasets' > barplot2(VADeaths, plot = FALSE) [1] 0.7 1.9 3.1 4.3 > barplot2(VADeaths, plot = FALSE, beside = TRUE) [,1] [,2] [,3] [,4] [1,] 1.5 7.5 13.5 19.5 [2,] 2.5 8.5 14.5 20.5 [3,] 3.5 9.5 15.5 21.5 [4,] 4.5 10.5 16.5 22.5 [5,] 5.5 11.5 17.5 23.5 > > mp <- barplot2(VADeaths) # default > tot <- colMeans(VADeaths) > text(mp, tot + 3, format(tot), xpd = TRUE, col = "blue") > barplot2(VADeaths, beside = TRUE, + col = c("lightblue", "mistyrose", "lightcyan", + "lavender", "cornsilk"), + legend = rownames(VADeaths), ylim = c(0, 100)) > title(main = "Death Rates in Virginia", font.main = 4) > > # Example with confidence intervals and grid > hh <- t(VADeaths)[, 5:1] > mybarcol <- "gray20" > ci.l <- hh * 0.85 > ci.u <- hh * 1.15 > mp <- barplot2(hh, beside = TRUE, + col = c("lightblue", "mistyrose", + "lightcyan", "lavender"), + legend = colnames(VADeaths), ylim = c(0, 100), + main = "Death Rates in Virginia", font.main = 4, + sub = "Faked 95 percent error bars", col.sub = mybarcol, + cex.names = 1.5, plot.ci = TRUE, ci.l = ci.l, ci.u = ci.u, + plot.grid = TRUE) > mtext(side = 1, at = colMeans(mp), line = -2, + text = paste("Mean", formatC(colMeans(hh))), col = "red") > box() > > # Example with horizontal bars, grid and logarithmic x axis > barplot2(1:10 , log = "x", plot.grid = TRUE, grid.inc = 10, + xlim = c(0.5, 20), horiz = TRUE, cex.axis = 0.9, + prcol = "gray95") > box() > > # Bar shading example > barplot2(VADeaths, angle = 15 + 10 * 1:5, density = 20, col = "black", + legend = rownames(VADeaths)) > title(main = list("Death Rates in Virginia", font = 4)) > > # border : > barplot2(VADeaths, border = "dark blue") > > > > cleanEx(); ..nameEx <- "boxplot.n" > > ### * boxplot.n > > flush(stderr()); flush(stdout()) > > ### Name: boxplot.n > ### Title: Produce a Boxplot Annotated with the Number of Observations > ### Aliases: boxplot.n > ### Keywords: hplot > > ### ** Examples > > data(state) > > # n's at bottom > boxplot.n( state.area ~ state.region) > > # n's at top > boxplot.n( state.area ~ state.region, top=TRUE) > > # small red text > boxplot.n( state.area ~ state.region, shrink=0.8, textcolor="red") > > > > cleanEx(); ..nameEx <- "colorpanel" > > ### * colorpanel > > flush(stderr()); flush(stdout()) > > ### Name: colorpanel > ### Title: Generate a smoothly varying set of colors > ### Aliases: colorpanel redgreen greenred bluered redblue > ### Keywords: color > > ### ** Examples > > > showpanel <- function(col) + { + image(z=matrix(1:100, ncol=1), col=col, xaxt="n", yaxt="n" ) + } > > par(mfrow=c(2,3)) > > showpanel(colorpanel(8,"red","black","green")) > # note the duplicatation of black at the center, using an odd > # number of elements resolves this: > showpanel(colorpanel(9,"red","black","green")) > > showpanel(greenred(64)) > showpanel(redgreen(64)) > showpanel(bluered(64)) > showpanel(redblue(64)) > > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "heatmap.2" > > ### * heatmap.2 > > flush(stderr()); flush(stdout()) > > ### Name: heatmap.2 > ### Title: Draw a Heat Map > ### Aliases: heatmap.2 > ### Keywords: hplot > > ### ** Examples > > data(mtcars) > x <- as.matrix(mtcars) > rc <- rainbow(nrow(x), start=0, end=.3) > cc <- rainbow(ncol(x), start=0, end=.3) > hv <- heatmap.2(x, col=cm.colors(256), scale="column", + RowSideColors=rc, ColSideColors=cc, margin=c(5, 10), + xlab="specification variables", ylab= "Car Models", + main="heatmap(, ..., scale=\"column\")", + tracecol="green", density="density") > > str(hv) # the two re-ordering index vectors List of 2 $ rowInd: int [1:32] 31 17 16 15 5 25 29 24 7 6 ... $ colInd: int [1:11] 2 9 8 11 6 5 10 7 1 4 ... > > data(attitude) > round(Ca <- cor(attitude), 2) rating complaints privileges learning raises critical advance rating 1.00 0.83 0.43 0.62 0.59 0.16 0.16 complaints 0.83 1.00 0.56 0.60 0.67 0.19 0.22 privileges 0.43 0.56 1.00 0.49 0.45 0.15 0.34 learning 0.62 0.60 0.49 1.00 0.64 0.12 0.53 raises 0.59 0.67 0.45 0.64 1.00 0.38 0.57 critical 0.16 0.19 0.15 0.12 0.38 1.00 0.28 advance 0.16 0.22 0.34 0.53 0.57 0.28 1.00 > symnum(Ca) # simple graphic rt cm p l rs cr a rating 1 complaints + 1 privileges . . 1 learning , . . 1 raises . , . , 1 critical . 1 advance . . . 1 attr(,"legend") [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1 > > # with reorder > heatmap.2(Ca, symm=TRUE, margin=c(6, 6), trace="none" ) > > # without reorder > heatmap.2(Ca, Rowv=FALSE, symm=TRUE, margin=c(6, 6), trace="none" ) > > ## For variable clustering, rather use distance based on cor(): > data(USJudgeRatings) > symnum( cU <- cor(USJudgeRatings) ) CO I DM DI CF DE PR F O W PH R CONT 1 INTG 1 DMNR B 1 DILG + + 1 CFMG + + B 1 DECI + + B B 1 PREP + + B B B 1 FAMI + + B * * B 1 ORAL * * B B * B B 1 WRIT * + B * * B B B 1 PHYS , , + + + + + + + 1 RTEN * * * * * B * B B * 1 attr(,"legend") [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1 > > hU <- heatmap.2(cU, Rowv=FALSE, symm=TRUE, col=topo.colors(16), + distfun=function(c) as.dist(1 - c), trace="none") > > ## The Correlation matrix with same reordering: > hM <- format(round(cU[hU[[1]], hU[[2]]], 2)) > hM CONT INTG DMNR PHYS DILG CFMG DECI RTEN ORAL CONT " 1.00" "-0.13" "-0.15" " 0.05" " 0.01" " 0.14" " 0.09" "-0.03" "-0.01" INTG "-0.13" " 1.00" " 0.96" " 0.74" " 0.87" " 0.81" " 0.80" " 0.94" " 0.91" DMNR "-0.15" " 0.96" " 1.00" " 0.79" " 0.84" " 0.81" " 0.80" " 0.94" " 0.91" PHYS " 0.05" " 0.74" " 0.79" " 1.00" " 0.81" " 0.88" " 0.87" " 0.91" " 0.89" DILG " 0.01" " 0.87" " 0.84" " 0.81" " 1.00" " 0.96" " 0.96" " 0.93" " 0.95" CFMG " 0.14" " 0.81" " 0.81" " 0.88" " 0.96" " 1.00" " 0.98" " 0.93" " 0.95" DECI " 0.09" " 0.80" " 0.80" " 0.87" " 0.96" " 0.98" " 1.00" " 0.92" " 0.95" RTEN "-0.03" " 0.94" " 0.94" " 0.91" " 0.93" " 0.93" " 0.92" " 1.00" " 0.98" ORAL "-0.01" " 0.91" " 0.91" " 0.89" " 0.95" " 0.95" " 0.95" " 0.98" " 1.00" WRIT "-0.04" " 0.91" " 0.89" " 0.86" " 0.96" " 0.94" " 0.95" " 0.97" " 0.99" PREP " 0.01" " 0.88" " 0.86" " 0.85" " 0.98" " 0.96" " 0.96" " 0.95" " 0.98" FAMI "-0.03" " 0.87" " 0.84" " 0.84" " 0.96" " 0.94" " 0.94" " 0.94" " 0.98" WRIT PREP FAMI CONT "-0.04" " 0.01" "-0.03" INTG " 0.91" " 0.88" " 0.87" DMNR " 0.89" " 0.86" " 0.84" PHYS " 0.86" " 0.85" " 0.84" DILG " 0.96" " 0.98" " 0.96" CFMG " 0.94" " 0.96" " 0.94" DECI " 0.95" " 0.96" " 0.94" RTEN " 0.97" " 0.95" " 0.94" ORAL " 0.99" " 0.98" " 0.98" WRIT " 1.00" " 0.99" " 0.99" PREP " 0.99" " 1.00" " 0.99" FAMI " 0.99" " 0.99" " 1.00" > > # now with the correlation matrix on the plot itself > > heatmap.2(cU, Rowv=FALSE, symm=TRUE, col=rev(heat.colors(16)), + distfun=function(c) as.dist(1 - c), trace="none", + cellnote=hM) > > ## genechip data examples > ## Not run: > ##D library(affy) > ##D data(SpikeIn) > ##D pms <- SpikeIn@pm > ##D > ##D # just the data, scaled across rows > ##D heatmap.2(pms, col=rev(heat.colors(16)), main="SpikeIn@pm", > ##D xlab="Relative Concentration", ylab="Probeset", > ##D scale="row") > ##D > ##D # fold change vs "12.50" sample > ##D data <- pms / pms[, "12.50"] > ##D data <- ifelse(data>1, data, -1/data) > ##D heatmap.2(data, breaks=16, col=redgreen, tracecol="blue", > ##D main="SpikeIn@pm Fold Changes\nrelative to 12.50 sample", > ##D xlab="Relative Concentration", ylab="Probeset") > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "hist2d" > > ### * hist2d > > flush(stderr()); flush(stdout()) > > ### Name: hist2d > ### Title: Compute and Plot a 2-Dimensional Histogram > ### Aliases: hist2d > ### Keywords: dplot hplot > > ### ** Examples > > # example data, bivariate normal, no correlation > x <- rnorm(2000, sd=4) > y <- rnorm(2000, sd=1) > > # separate scales for each axis, this looks circular > hist2d(x,y) > > # same scale for each axis, this looks oval > hist2d(x,y, same.scale=TRUE) > > # use different # bins in each dimension > hist2d(x,y, same.scale=TRUE, nbins=c(100,200) ) > > # use the hist2d function to create inputs for a perspective plot ... > h2d <- hist2d(x,y,show=FALSE, same.scale=TRUE, nbins=c(20,30)) > persp( h2d$x, h2d$y, h2d$counts, + ticktype="detailed", theta=30, phi=30, + expand=0.5, shade=0.5, col="cyan", ltheta=-30) > > # for contour (line) plot ... > contour( h2d$x, h2d$y, h2d$counts, nlevels=4 ) > > # for a filled contour plot ... > filled.contour( h2d$x, h2d$y, h2d$counts, nlevels=4, + col=gray((4:0)/4) ) > > > > cleanEx(); ..nameEx <- "lowess" > > ### * lowess > > flush(stderr()); flush(stdout()) > > ### Name: lowess > ### Title: Scatter Plot Smoothing > ### Aliases: lowess lowess.default lowess.formula lowess > ### Keywords: smooth > > ### ** Examples > > data(cars) > > # default method > plot(cars, main = "lowess(cars)") > lines(lowess(cars), col = 2) > lines(lowess(cars, f=.2), col = 3) > legend(5, 120, c(paste("f = ", c("2/3", ".2"))), lty = 1, col = 2:3) > > # formula method > plot(dist ~ speed, data=cars, main = "lowess(cars)") > lines(lowess(dist ~ speed, data=cars), col = 2) > lines(lowess(dist ~ speed, data=cars, f=.2), col = 3) > legend(5, 120, c(paste("f = ", c("2/3", ".2"))), lty = 1, col = 2:3) > > > > > cleanEx(); ..nameEx <- "ooplot" > > ### * ooplot > > flush(stderr()); flush(stdout()) > > ### Name: ooplot.default > ### Title: Create an OpenOffice style plot > ### Aliases: ooplot.default ooplot > ### Keywords: hplot > > ### ** Examples > > data(VADeaths, package = "base") Warning in data(VADeaths, package = "base") : datasets have been moved from package 'base' to package 'datasets' > > VADeaths <- cbind( Age=c(50,55,60,65,70), VADeaths) > > mp <- ooplot(VADeaths) # default > mp <- ooplot(VADeaths, type="xyplot") # same as default > mp <- ooplot(VADeaths, type="linear") # linear scale > mp <- ooplot(VADeaths, type="linear", log="y") # log scale on y axis > mp <- ooplot(VADeaths, type="barplot") # barplot > mp <- ooplot(VADeaths, type="stackbar") # stacked > > tot <- colMeans(VADeaths[,-1]) > ooplot(VADeaths, + col = c("lightblue", "mistyrose", "lightcyan", "lavender"), + legend = colnames(VADeaths)[-1], ylim = c(0, 100), + type="barplot", cex.values=0.75) > title(main = "Death Rates in Virginia", font.main = 4) > > ## > ## Capability demo > ## > ## examples for the ooplot routine > ## > ## create some test data > test1 <- data.frame(x=c(0,1,2,3,4), lin=c(0,1,2,3,4)) > test2 <- data.frame(x=c(0,1,2,3,4), par=c(0,1,4,9,16)) > test3 <- data.frame(x=c(-2,-1,0,1,2),y2=c(4,1,0,1,4)) > ## single line test example > test1f <- test1 > ## two column example > test2f <- merge(test1,test2,by.x="x",all=TRUE,sort=TRUE) > ## three column example > test3f <- merge(test2f,test3,by.x="x",all=TRUE,sort=TRUE) > ## subset, single row, example > test5r <- test3f[5,] > > ## > ## xyplot, linear, barplot, stackbar > mat <- matrix(c(1:16),4,4,byrow=TRUE) > layout(mat) > > ooplot(test1f,type="barplot",col=c("red")) > title(main="barplot") > ooplot(test2f,type="barplot",col=c("red","blue")) > ooplot(test3f,type="barplot",col=c("red","blue","green")) > ooplot(test5r,type="barplot",col=c("red","blue","green")) > > ooplot(test1f,type="xyplot",col=c("red")) > title(main="xyplot") > ooplot(test2f,type="xyplot",col=c("red","blue")) > ooplot(test3f,type="xyplot",col=c("red","blue","green")) > ooplot(test5r,type="xyplot",col=c("red","blue","green")) > > ooplot(test1f,type="linear",col=c("red")) > title(main="linear") > ooplot(test2f,type="linear",col=c("red","blue")) > ooplot(test3f,type="linear",col=c("red","blue","green")) > ooplot(test5r,type="linear",col=c("red","blue","green")) > > ooplot(test1f,type="stackbar",col=c("red")) > title(main="stackbar") > ooplot(test2f,type="stackbar",col=c("red","blue")) > ooplot(test3f,type="stackbar",col=c("red","blue","green")) > ooplot(test5r,type="stackbar",col=c("red","blue","green")) > > > > > cleanEx(); ..nameEx <- "overplot" > > ### * overplot > > flush(stderr()); flush(stdout()) > > ### Name: overplot > ### Title: Plot multiple variables on the same region, with appropriate > ### axes > ### Aliases: overplot panel.overplot > ### Keywords: hplot > > ### ** Examples > > > # Example teratogenicity rtPCR data > data(rtPCR) > > # same scale > overplot( RQ ~ Conc..ug.ml. | Test.Substance, + data=rtPCR, + subset=Detector=="ProbeType 7" & Conc..ug.ml. > 0, + same.scale=TRUE, + log="xy", + f=3/4, + main="Detector=ProbeType 7", + xlab="Concentration (ug/ml)", + ylab="Relative Gene Quantification" + ) > > # different scales, but force lower limit to 0.01 > overplot( RQ ~ Conc..ug.ml. | Test.Substance, + data=rtPCR, + subset=Detector=="ProbeType 7" & Conc..ug.ml. > 0, + log="xy", + f=3/4, + main="Detector=ProbeType 7", + xlab="Concentration (ug/ml)", + ylab="Relative Gene Quantification", + min.y=0.01 + ) > > > > > cleanEx(); ..nameEx <- "plotCI" > > ### * plotCI > > flush(stderr()); flush(stdout()) > > ### Name: plotCI > ### Title: Plot Error Bars and Confidence Intervals > ### Aliases: plotCI > ### Keywords: hplot > > ### ** Examples > > > # plot means and > data(state) > tmp <- split(state.area, state.region) > means <- sapply(tmp, mean) > stdev <- sqrt(sapply(tmp, var)) > n <- sapply(tmp,length) > ciw <- qt(0.975, n) * stdev / sqrt(n) > > # plain > plotCI(x=means, uiw=ciw) Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped > > # prettier > plotCI(x=means, uiw=ciw, col="black", barcol="blue", lwd=1) Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped > > # give mean values > plotCI(x=means, uiw=ciw, col="black", barcol="blue", + labels=round(means,-3), xaxt="n", xlim=c(0,5) ) Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped > axis(side=1, at=1:4, labels=names(tmp), cex=0.7) > > # better yet, just use plotmeans ... # > plotmeans( state.area ~ state.region ) Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped > > > > > cleanEx(); ..nameEx <- "plotmeans" > > ### * plotmeans > > flush(stderr()); flush(stdout()) > > ### Name: plotmeans > ### Title: Plot Group Means and Confidence Intervals > ### Aliases: plotmeans > ### Keywords: hplot > > ### ** Examples > > > # show comparison with boxplot > data(state) > plotmeans(state.area ~ state.region) Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped > > # show some color and mean labels > plotmeans(state.area ~ state.region, + mean.labels=TRUE, digits=-3, + col="red", connect=FALSE) Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped > > # show how to specify which means should be connected > plotmeans(state.area ~ state.region, connect=list(1:2, 3:4), + ccol="red", pch=7 ) Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped > > # more complicated example showing how to show an interaction > data(esoph) > par(las=2, # use perpendicular axis labels + mar=c(10.1,4.1,4.1,2.1), # create enough space for long x labels + mgp=c(8,1,0) # move x axis legend down to avoid overlap + ) > plotmeans(ncases/ncontrols ~ interaction(agegp , alcgp, sep =" "), + connect=list(1:6,7:12,13:18,19:24), + barwidth=2, + col="dark green", + data=esoph, + xlab="Age Group and Alcohol Consumption", + ylab="# Cases / # Controls", + main=c("Fraction of Cases for by Age and Alcohol Consumption", + "Ile-et-Vilaine Esophageal Cancer Study") + ) Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: zero-length arrow is of indeterminate angle and so skipped Warning: parameter "main" could not be set in high-level plot() function > abline(v=c(6.5, 12.5, 18.5), lty=2) > > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "qqnorm.aov" > > ### * qqnorm.aov > > flush(stderr()); flush(stdout()) > > ### Name: qqnorm.aov > ### Title: Makes a half or full normal plot for the effects from an aov > ### model > ### Aliases: qqnorm.aov > ### Keywords: hplot design > > ### ** Examples > > library(MASS) > data(npk) > npk.aov <- aov(yield ~ block + N*P*K, npk) > qqnorm(npk.aov) > if (dev.interactive()) qqnorm(npk.aov, omit=2:6, label=TRUE) > > > > cleanEx(); ..nameEx <- "rich.color" > > ### * rich.color > > flush(stderr()); flush(stdout()) > > ### Name: rich.colors > ### Title: Rich color palettes > ### Aliases: rich.colors > ### Keywords: color > > ### ** Examples > > m <- matrix(1:120+rnorm(120), nrow=15, ncol=8) > opar <- par(bg="gray", mfrow=c(1,2)) > matplot(m, type="l", lty=1, lwd=3, col=rich.colors(8)) > matplot(m, type="l", lty=1, lwd=3, col=rich.colors(8,"blues")) > par(opar) > > barplot(rep(1,100), col=rich.colors(100), space=0, border=0, axes=FALSE) > barplot(rep(1,20), col=rich.colors(40)[11:30]) # choose subset > > rich.colors(100, plot=TRUE, rgb=TRUE) # describe rgb recipe 1 2 3 4 5 6 7 8 "#000040" "#000047" "#00004F" "#000057" "#000060" "#000069" "#000073" "#00007D" 9 10 11 12 13 14 15 16 "#000087" "#000091" "#00009C" "#0000A6" "#0000B0" "#0000BA" "#0000C4" "#0000CE" 17 18 19 20 21 22 23 24 "#000AD6" "#0015DF" "#0020E6" "#002BED" "#0035F2" "#003FF7" "#0049FB" "#0053FD" 25 26 27 28 29 30 31 32 "#005CFF" "#0065FF" "#006EFE" "#0076FC" "#007FF9" "#0087F5" "#008FF0" "#0096E9" 33 34 35 36 37 38 39 40 "#009DE2" "#00A4DB" "#00ABD2" "#00B2C9" "#00B8BF" "#00BEB5" "#00C3AB" "#01C9A1" 41 42 43 44 45 46 47 48 "#01CE97" "#01D38C" "#01D882" "#02DC78" "#03E06E" "#04E465" "#06E85C" "#08EB53" 49 50 51 52 53 54 55 56 "#0CEE4B" "#10F143" "#17F43C" "#1FF635" "#2AF82F" "#38FA2A" "#49FB25" "#5DFC20" 57 58 59 60 61 62 63 64 "#73FD1C" "#89FE18" "#9FFF15" "#B3FF12" "#C5FF0F" "#D3FF0D" "#DEFE0B" "#E7FD09" 65 66 67 68 69 70 71 72 "#EEFC08" "#F3FB06" "#F6F905" "#F9F704" "#FBF504" "#FCF303" "#FDF002" "#FDED02" 73 74 75 76 77 78 79 80 "#FEEA02" "#FEE701" "#FEE301" "#FFDF01" "#FFDB01" "#FFD701" "#FFD200" "#FFCD00" 81 82 83 84 85 86 87 88 "#FFC800" "#FFC200" "#FFBD00" "#FFB700" "#FFB000" "#FFAA00" "#FFA300" "#FF9C00" 89 90 91 92 93 94 95 96 "#FF9500" "#FF8D00" "#FF8500" "#FF7D00" "#FF7500" "#FF6C00" "#FF6300" "#FF5A00" 97 98 99 100 "#FF5100" "#FF4700" "#FF3D00" "#FF3300" attr(,"rgb.matrix") red green blue 1 2.061154e-09 0.00000000 2.493875e-01 2 2.935275e-09 0.00000000 2.783764e-01 3 4.180106e-09 0.00000000 3.093291e-01 4 5.952861e-09 0.00000000 3.421682e-01 5 8.477429e-09 0.00000000 3.767811e-01 6 1.207265e-08 0.00000000 4.130182e-01 7 1.719258e-08 0.00000000 4.506921e-01 8 2.448384e-08 0.00000000 4.895773e-01 9 3.486727e-08 0.00000000 5.294114e-01 10 4.965425e-08 0.00000000 5.698963e-01 11 7.071228e-08 0.00000000 6.107015e-01 12 1.007009e-07 0.00000000 6.514675e-01 13 1.434075e-07 0.00000000 6.918106e-01 14 2.042256e-07 0.00000000 7.313280e-01 15 2.908363e-07 0.00000000 7.696049e-01 16 4.141780e-07 0.00000000 8.062209e-01 17 5.898280e-07 0.03909805 8.407578e-01 18 8.399699e-07 0.08286909 8.728072e-01 19 1.196195e-06 0.12561983 9.019790e-01 20 1.703493e-06 0.16735027 9.279084e-01 21 2.425931e-06 0.20806040 9.502642e-01 22 3.454748e-06 0.24775023 9.687557e-01 23 4.919876e-06 0.28641975 9.831387e-01 24 7.006349e-06 0.32406897 9.932211e-01 25 9.977665e-06 0.36069789 9.988670e-01 26 1.420907e-05 0.39630650 1.000000e+00 27 2.023491e-05 0.43089481 9.966048e-01 28 2.881616e-05 0.46446281 9.887273e-01 29 4.103640e-05 0.49701051 9.764741e-01 30 5.843864e-05 0.52853790 9.600094e-01 31 8.322002e-05 0.55904500 9.395522e-01 32 1.185089e-04 0.58853178 9.153705e-01 33 1.687592e-04 0.61699827 8.877763e-01 34 2.403117e-04 0.64444444 8.571183e-01 35 3.421914e-04 0.67087032 8.237751e-01 36 4.872418e-04 0.69627589 7.881468e-01 37 6.937345e-04 0.72066116 7.506477e-01 38 9.876521e-04 0.74402612 7.116982e-01 39 1.405920e-03 0.76637078 6.717167e-01 40 2.000968e-03 0.78769513 6.311129e-01 41 2.847149e-03 0.80799918 5.902807e-01 42 4.049716e-03 0.82728293 5.495924e-01 43 5.757286e-03 0.84554637 5.093936e-01 44 8.178943e-03 0.86278951 4.699989e-01 45 1.160732e-02 0.87901235 4.316888e-01 46 1.644893e-02 0.89421488 3.947075e-01 47 2.326254e-02 0.90839710 3.592614e-01 48 3.280439e-02 0.92155902 3.255190e-01 49 4.607551e-02 0.93370064 2.936113e-01 50 6.435824e-02 0.94482196 2.636330e-01 51 8.921706e-02 0.95492297 2.356446e-01 52 1.224214e-01 0.96400367 2.096745e-01 53 1.657349e-01 0.97206408 1.857225e-01 54 2.205221e-01 0.97910417 1.637623e-01 55 2.871859e-01 0.98512397 1.437454e-01 56 3.645764e-01 0.99012346 1.256044e-01 57 4.496660e-01 0.99410264 1.092562e-01 58 5.378065e-01 0.99706152 9.460584e-02 59 6.236455e-01 0.99900010 8.154935e-02 60 7.023651e-01 0.99991838 6.997673e-02 61 7.706741e-01 0.99981635 5.977470e-02 62 8.271635e-01 0.99869401 5.082902e-02 63 8.720483e-01 0.99655137 4.302657e-02 64 9.065930e-01 0.99338843 3.625704e-02 65 9.325328e-01 0.98920518 3.041435e-02 66 9.516531e-01 0.98400163 2.539775e-02 67 9.655548e-01 0.97777778 2.111265e-02 68 9.755619e-01 0.97053362 1.747112e-02 69 9.827137e-01 0.96226916 1.439227e-02 70 9.877987e-01 0.95298439 1.180235e-02 71 9.914010e-01 0.94267932 9.634707e-03 72 9.939463e-01 0.93135394 7.829589e-03 73 9.957414e-01 0.91900826 6.333883e-03 74 9.970058e-01 0.90564228 5.100723e-03 75 9.978956e-01 0.89125599 4.089065e-03 76 9.985214e-01 0.87584940 3.263225e-03 77 9.989612e-01 0.85942251 2.592391e-03 78 9.992704e-01 0.84197531 2.050145e-03 79 9.994875e-01 0.82350781 1.613985e-03 80 9.996401e-01 0.80402000 1.264867e-03 81 9.997472e-01 0.78351189 9.867810e-04 82 9.998225e-01 0.76198347 7.663503e-04 83 9.998754e-01 0.73943475 5.924675e-04 84 9.999125e-01 0.71586573 4.559659e-04 85 9.999385e-01 0.69127640 3.493259e-04 86 9.999568e-01 0.66566677 2.664157e-04 87 9.999697e-01 0.63903683 2.022644e-04 88 9.999787e-01 0.61138659 1.528656e-04 89 9.999851e-01 0.58271605 1.150087e-04 90 9.999895e-01 0.55302520 8.613548e-05 91 9.999926e-01 0.52231405 6.421909e-05 92 9.999948e-01 0.49058259 4.766251e-05 93 9.999964e-01 0.45783083 3.521439e-05 94 9.999974e-01 0.42405877 2.589966e-05 95 9.999982e-01 0.38926640 1.896263e-05 96 9.999987e-01 0.35345373 1.382082e-05 97 9.999991e-01 0.31662075 1.002766e-05 98 9.999994e-01 0.27876747 7.242624e-06 99 9.999996e-01 0.23989389 5.207424e-06 100 9.999997e-01 0.20000000 3.727181e-06 > > par(mfrow=c(2,2)) > barplot(m, main="\nheat.colors") > barplot(m, col=1:15, main="\ndefault palette") > barplot(m, col=rich.colors(15), main="\nrich.colors") > barplot(m, col=rainbow(15), main="\nrainbow") > par(opar) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "rtPCR" > > ### * rtPCR > > flush(stderr()); flush(stdout()) > > ### Name: rtPCR > ### Title: Teratogenesis rtPCR data > ### Aliases: rtPCR > ### Keywords: datasets > > ### ** Examples > > data(rtPCR) > > # same scale > overplot( RQ ~ Conc..ug.ml. | Test.Substance, + data=rtPCR, + subset=Detector=="ProbeType 7" & Conc..ug.ml. > 0, + same.scale=TRUE, + log="xy", + f=3/4, + main="Detector=ProbeType 7", + xlab="Concentration (ug/ml)", + ylab="Relative Gene Quantification" + ) > > # different scales, but force lower limit to 0.01 > overplot( RQ ~ Conc..ug.ml. | Test.Substance, + data=rtPCR, + subset=Detector=="ProbeType 7" & Conc..ug.ml. > 0, + log="xy", + f=3/4, + main="Detector=ProbeType 7", + xlab="Concentration (ug/ml)", + ylab="Relative Gene Quantification", + min.y=0.01 + ) > > > > cleanEx(); ..nameEx <- "sinkplot" > > ### * sinkplot > > flush(stderr()); flush(stdout()) > > ### Name: sinkplot > ### Title: Send textual R output to a graphics device > ### Aliases: sinkplot > ### Keywords: hplot > > ### ** Examples > > ## Not run: > ##D set.seed(12456) > ##D x <- factor(sample( LETTERS[1:5], 50, replace=TRUE)) > ##D y <- rnorm(50, mean=as.numeric(x), sd=1) > ##D > ##D par(mfrow=c(1,2)) > ##D boxplot(y~x, col="darkgreen") > ##D > ##D sinkplot() > ##D anova(lm(y~x)) > ##D sinkplot("plot",col="darkgreen") > ## End(Not run) > > > > cleanEx(); ..nameEx <- "smartlegend" > > ### * smartlegend > > flush(stderr()); flush(stdout()) > > ### Name: smartlegend > ### Title: Place a legend in a specified logical ("top","bottom", "left", > ### "right", etc) location on a plot. > ### Aliases: smartlegend > ### Keywords: hplot > > ### ** Examples > > > x <- rnorm(100) > y <- rnorm(100, x^2 ) > plot(x,y) > abline( lm(y~x), col="red", lty=1, type="b") # regression fit > lines( lowess(y~x), col="blue", lty=2, type="b") # lowess fit > > smartlegend(x="center", y="top", + c("Regression","Locally Linear Smooth"), + col=c("red","blue"), lty=1:2) > > > > > cleanEx(); ..nameEx <- "space" > > ### * space > > flush(stderr()); flush(stdout()) > > ### Name: space > ### Title: Space points in an x-y plot so they don't overlap. > ### Aliases: space > ### Keywords: dplot > > ### ** Examples > > x <- rep(1:5, 10) > y <- round(rnorm(length(x),x)) > > prepar <- par("mfrow") > par(mfrow=c(1,3)) > > # standard x-y plot: noverlapping points are hidden > plot(x,y) > title("Standard Plot") > > # 'spaced' plot: overlapping points are spread out and visible > plot(space(x,y)) > title("Plot with 'space'") > > # 'spaced' plot: overlapping points are spread out along y and visible > plot(space(x,y, direction='y')) > title("Plot with 'space', direction='y' ") > > # 'sunflower' plot, another approach, overlapping points are > # indicated via petals > sunflowerplot(x,y) > title("Sunflower Plot") > > ## Don't show: > # check that missign values correctly handled > x <- c(x,NA) > y <- c(y,NA) > plot(space(x,y)) > > ## End Don't show > > par(mfrow=prepar) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "textplot" > > ### * textplot > > flush(stderr()); flush(stdout()) > > ### Name: textplot > ### Title: Display text information in a graphics plot. > ### Aliases: textplot textplot.default textplot.character textplot.matrix > ### textplot.data.frame > ### Keywords: hplot > > ### ** Examples > > ## Not run: > ##D ### simple examples > ##D # show R version information > ##D textplot(version) > ##D > ##D # show the alphabet as a single string > ##D textplot( paste(letters[1:26], collapse=" ") ) > ##D > ##D # show the alphabet as a matrix > ##D textplot( matrix(letters[1:26], ncol=2)) > ##D > ##D ### Make a nice 4 way display with two plots and two text summaries > ##D > ##D data(iris) > ##D par(mfrow=c(2,2)) > ##D plot( Sepal.Length ~ Species, data=iris, border="blue", col="cyan", > ##D main="Boxplot of Sepal Length by Species" ) > ##D plotmeans( Sepal.Length ~ Species, data=iris, barwidth=2, connect=FALSE, > ##D main="Means and 95% Confidence Intervals\nof Sepal Length by Species") > ##D > ##D info <- sapply( split(iris$Sepal.Length, iris$Species), > ##D function(x) round(c(Mean=mean(x), SD=sd(x), N=gdata::nobs(x)),2) ) > ##D > ##D textplot( info, valign="top" ) > ##D title("Sepal Length by Species") > ##D > ##D reg <- lm( Sepal.Length ~ Species, data=iris ) > ##D textplot( capture.output(summary(reg)), valign="top") > ##D title("Regression of Sepal Length by Species") > ##D > ##D par(mfrow=c(1,1)) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "wapply" > > ### * wapply > > flush(stderr()); flush(stdout()) > > ### Name: wapply > ### Title: Compute the Value of a Function Over a Local Region Of An X-Y > ### Plot > ### Aliases: wapply > ### Keywords: dplot > > ### ** Examples > > > #show local mean and inner 2-sd interval to help diagnose changing mean > #or variance structure > x <- 1:1000 > y <- rnorm(1000, mean=1, sd=1 + x/1000 ) > > plot(x,y) > lines(wapply(x,y,mean),col="red") > > CL <- function(x,sd) mean(x)+sd*sqrt(var(x)) > > lines(wapply(x,y,CL,sd= 1),col="blue") > lines(wapply(x,y,CL,sd=-1),col="blue") > lines(wapply(x,y,CL,sd= 2),col="green") > lines(wapply(x,y,CL,sd=-2),col="green") > > #show local mean and inner 2-sd interval to help diagnose changing mean > #or variance structure > x <- 1:1000 > y <- rnorm(1000, mean=x/1000, sd=1) > > plot(x,y) > lines(wapply(x,y,mean),col="red") > > CL <- function(x,sd) mean(x)+sd*sqrt(var(x)) > > lines(wapply(x,y,CL,sd= 1,method="fraction",width=1/20),col="blue") > lines(wapply(x,y,CL,sd=-1,method="fraction",width=1/20),col="blue") > lines(wapply(x,y,CL,sd= 2,method="nobs",width=250),col="green") > lines(wapply(x,y,CL,sd=-2,method="nobs",width=250),col="green") > > > > > ### *