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("plotrix-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('plotrix') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "axis.break" > > ### * axis.break > > flush(stderr()); flush(stdout()) > > ### Name: axis.break > ### Title: Place a "break" mark on an axis > ### Aliases: axis.break > ### Keywords: misc > > ### ** Examples > > plot(3:10) > # put a break at the default axis and position > axis.break() > axis.break(2,2.9,style="zigzag") > > > > cleanEx(); ..nameEx <- "barplot.symbol.default" > > ### * barplot.symbol.default > > flush(stderr()); flush(stdout()) > > ### Name: barplot.symbol.default > ### Title: barplot filled with symbols > ### Aliases: barplot.symbol.default > ### Keywords: hplot > > ### ** Examples > > set.seed(1001) > bvals <- matrix(rpois(12,20),nrow=3) > b <- barplot.symbol.default(bvals) > > > > cleanEx(); ..nameEx <- "boxed.labels" > > ### * boxed.labels > > flush(stderr()); flush(stdout()) > > ### Name: boxed.labels > ### Title: Place labels in boxes > ### Aliases: boxed.labels > ### Keywords: misc > > ### ** Examples > > x<-rnorm(10) > y<-rnorm(10) > plot(x,y,type="p") > nums<-c("one","two","three","four","five","six","seven","eight","nine","ten") > boxed.labels(x,y-0.1,nums) > readline("Press to continue") Press to continue # now label a barplot [1] "# now label a barplot" > xpos<-barplot(c(1,3,2,4)) > boxed.labels(xpos,0.5,nums[1:4]) > > > > cleanEx(); ..nameEx <- "clean.args" > > ### * clean.args > > flush(stderr()); flush(stdout()) > > ### Name: clean.args > ### Title: Remove inappropriate arguments from an argument list > ### Aliases: clean.args remove.args > ### Keywords: programming > > ### ** Examples > > tststr <- list(n=2,mean=0,sd=1,foo=4,bar=6) > clean.args(tststr,rnorm) $n [1] 2 $mean [1] 0 $sd [1] 1 > try(do.call("rnorm",tststr)) Error in rnorm(n = 2, mean = 0, sd = 1, foo = 4, bar = 6) : unused argument(s) (foo ...) > do.call("rnorm",clean.args(tststr,rnorm)) [1] -0.6264538 0.1836433 > remove.args(tststr,rnorm) $foo [1] 4 $bar [1] 6 > ## add example of combining arg. lists? > > > > cleanEx(); ..nameEx <- "clock24.plot" > > ### * clock24.plot > > flush(stderr()); flush(stdout()) > > ### Name: clock24.plot > ### Title: clock24.plot > ### Aliases: clock24.plot > ### Keywords: misc > > ### ** Examples > > testlen<-rnorm(24)*2+5 > testpos<-0:23+rnorm(24)/4 > clock24.plot(testlen,testpos,main="Test Clock24",show.grid=FALSE, + line.col="green",lwd=3) > par(ask=TRUE) > # now do a 'daylight' plot > clock24.plot(testlen[5:19],testpos[5:19],main="Test Clock24 daytime", + line.col="blue",lwd=3) Hit to see next plot: par(ask=FALSE)> > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "color.gradient" > > ### * color.gradient > > flush(stderr()); flush(stdout()) > > ### Name: color.gradient > ### Title: color.gradient > ### Aliases: color.gradient > ### Keywords: misc > > ### ** Examples > > # try it with red endpoints, green midpoints, and a blue vector longer > # than 'nslices' > color.gradient(c(0,1),c(1,0.6,0.4,0.3,0),seq(0.1,0.6,length=60)) [1] "#00FF1A" "#05F71C" "#0AEE1E" "#10E620" "#15DE22" "#1AD524" "#1FCD26" [8] "#24C529" "#2ABC2B" "#2FB42D" "#34AC2F" "#39A331" "#3E9B33" "#449636" [15] "#499238" "#4E8E3A" "#53893C" "#58853E" "#5E8140" "#637D43" "#687945" [22] "#6D7547" "#727049" "#786C4B" "#7D684D" "#826550" "#876352" "#8D6154" [29] "#925F56" "#975D58" "#9C5B5A" "#A1585C" "#A7565F" "#AC5461" "#B15263" [36] "#B65065" "#BB4E67" "#C14B69" "#C6456C" "#CB3E6E" "#D03870" "#D53272" [43] "#DB2C74" "#E02576" "#E51F79" "#EA197B" "#EF137D" "#F50C7F" "#FA0681" [50] "#FF0083" > > > > cleanEx(); ..nameEx <- "color.id" > > ### * color.id > > flush(stderr()); flush(stdout()) > > ### Name: color.id > ### Title: Identify closest match to a color > ### Aliases: color.id > ### Keywords: color > > ### ** Examples > > color.id("#cc00cc") [1] "magenta3" > > > > cleanEx(); ..nameEx <- "color.scale" > > ### * color.scale > > flush(stderr()); flush(stdout()) > > ### Name: color.scale > ### Title: color.scale > ### Aliases: color.scale > ### Keywords: misc > > ### ** Examples > > # go from green to red with a constant blue value > x<-rnorm(20) > y<-rnorm(20) > # use y for the color scale > plot(x,y,col=color.scale(y,c(0,1),c(1,0),0.3)) > > > > cleanEx(); ..nameEx <- "corner.loc" > > ### * corner.loc > > flush(stderr()); flush(stdout()) > > ### Name: corner.loc > ### Title: Find corner points and add labels in corners > ### Aliases: corner.loc corner.label > ### Keywords: aplot > > ### ** Examples > > plot(1:10,1:10) > corner.label("A") > corner.loc(1,1) $x [1] 9.874 $y [1] 9.874 > corner.label("B",y=-1,x=1) > > > > cleanEx(); ..nameEx <- "floating.pie" > > ### * floating.pie > > flush(stderr()); flush(stdout()) > > ### Name: floating.pie > ### Title: Display a floating pie chart > ### Aliases: floating.pie > ### Keywords: misc > > ### ** Examples > > pieval<-c(2,4,6,8) > plot(1:5,type="n") > floating.pie(3,3,pieval) [1] 0.3141593 1.2566371 2.8274334 5.0265482 > > > > cleanEx(); ..nameEx <- "gantt.chart" > > ### * gantt.chart > > flush(stderr()); flush(stdout()) > > ### Name: gantt.chart > ### Title: Display a Gantt chart > ### Aliases: gantt.chart > ### Keywords: misc > > ### ** Examples > > Ymd.format<-"%Y/%m/%d" > gantt.info<-list(labels= + c("First task","Second task","Third task","Fourth task","Fifth task"), + starts= + as.POSIXct(strptime( + c("2004/01/01","2004/02/02","2004/03/03","2004/05/05","2004/09/09"), + format=Ymd.format)), + ends= + as.POSIXct(strptime( + c("2004/03/03","2004/05/05","2004/05/05","2004/08/08","2004/12/12"), + format=Ymd.format)), + priorities=c(1,2,3,4,5)) > gantt.chart(gantt.info,main="Calendar date Gantt chart") > > > > cleanEx(); ..nameEx <- "get.gantt.info" > > ### * get.gantt.info > > flush(stderr()); flush(stdout()) > > ### Name: get.gantt.info > ### Title: Gather the information to create a Gantt chart > ### Aliases: get.gantt.info > ### Keywords: misc > > ### ** Examples > > cat("Enter task times using HH:MM (hour:minute) format\n") Enter task times using HH:MM (hour:minute) format > get.gantt.info("%H:%M") Enter the label, start and finish time for each task. Default format for time is year/month/day e.g. 2005/2/22 Enter a blank label to end. Task label - $labels [1] NA $starts [1] NA $ends [1] NA $priorities [1] NA > > > cleanEx(); ..nameEx <- "get.soil.texture" > > ### * get.soil.texture > > flush(stderr()); flush(stdout()) > > ### Name: get.soil.texture > ### Title: get.soil.texture > ### Aliases: get.soil.texture > ### Keywords: misc > > ### ** Examples > > newsp<-get.soil.texture() Enter the label and proportions of sand, silt and clay for each soil sample. Enter a blank label to end. Soil sample label - # show the soil triangle Sand - get.soil.texture() Warning: NAs introduced by coercion Silt - # now plot the observations Warning: NAs introduced by coercion Clay - show.soil.texture(newsp) Warning: NAs introduced by coercion Soil sample label - > > > cleanEx(); ..nameEx <- "gradient.rect" > > ### * gradient.rect > > flush(stderr()); flush(stdout()) > > ### Name: gradient.rect > ### Title: gradient.rect > ### Aliases: gradient.rect > ### Keywords: misc > > ### ** Examples > > # get an empty box > plot(0:10,type="n",axes=FALSE) > # first try a "rainbow" > gradient.rect(1,0,3,6,reds=c(1,0), + greens=c(seq(0,1,length=10),seq(1,0,length=10)), + blues=c(0,1),gradient="y") [1] "#FF0000" "#FA0B05" "#F5160A" "#EF2110" "#EA2C15" "#E5371A" "#E0421F" [8] "#DB4D24" "#D5582A" "#D0632F" "#CB6E34" "#C67939" "#C1843E" "#BB8F44" [15] "#B69A49" "#B1A54E" "#ACB053" "#A7BB58" "#A1C65E" "#9CD163" "#97DC68" [22] "#92E76D" "#8DF272" "#87FD78" "#82FF7D" "#7DFF82" "#78FD87" "#72F28D" [29] "#6DE792" "#68DC97" "#63D19C" "#5EC6A1" "#58BBA7" "#53B0AC" "#4EA5B1" [36] "#499AB6" "#448FBB" "#3E84C1" "#3979C6" "#346ECB" "#2F63D0" "#2A58D5" [43] "#244DDB" "#1F42E0" "#1A37E5" "#152CEA" "#1021EF" "#0A16F5" "#050BFA" [50] "#0000FF" > # now a "danger gradient" > gradient.rect(4,0,6,6,c(seq(0,1,length=10),rep(1,10)), + c(rep(1,10),seq(1,0,length=10)),c(0,0),gradient="y") [1] "#00FF00" "#0BFF00" "#16FF00" "#21FF00" "#2CFF00" "#37FF00" "#42FF00" [8] "#4DFF00" "#58FF00" "#63FF00" "#6EFF00" "#79FF00" "#84FF00" "#8FFF00" [15] "#9AFF00" "#A5FF00" "#B0FF00" "#BBFF00" "#C6FF00" "#D1FF00" "#DCFF00" [22] "#E7FF00" "#F2FF00" "#FDFF00" "#FFFF00" "#FFFF00" "#FFFD00" "#FFF200" [29] "#FFE700" "#FFDC00" "#FFD100" "#FFC600" "#FFBB00" "#FFB000" "#FFA500" [36] "#FF9A00" "#FF8F00" "#FF8400" "#FF7900" "#FF6E00" "#FF6300" "#FF5800" [43] "#FF4D00" "#FF4200" "#FF3700" "#FF2C00" "#FF2100" "#FF1600" "#FF0B00" [50] "#FF0000" > # finally a real mess > gradient.rect(7,0,9,6,reds=c(1,0), + greens=rescale(rnorm(20),c(0,1)),blues=c(1,0), + gradient="y") [1] "#FF6AFF" "#FA7FFA" "#F594F5" "#EF95EF" "#EA7BEA" "#E560E5" "#E091E0" [8] "#DBD1DB" "#D5F6D5" "#D0D6D0" "#CBB5CB" "#C696C6" "#C178C1" "#BB61BB" [15] "#B683B6" "#B1A5B1" "#ACB8AC" "#A7BFA7" "#A1C5A1" "#9CC29C" "#97BD97" [22] "#92B292" "#8D9B8D" "#878587" "#82A582" "#7DD47D" "#78F378" "#72D672" [29] "#6DB96D" "#689E68" "#638463" "#5E685E" "#583F58" "#531653" "#4E294E" [36] "#498049" "#44D644" "#3EC43E" "#39A639" "#349134" "#2F922F" "#2A932A" [43] "#24A624" "#1FBE1F" "#1AD31A" "#15D015" "#10CD10" "#0AC80A" "#05C205" [50] "#00BC00" > > > > cleanEx(); ..nameEx <- "multhist" > > ### * multhist > > flush(stderr()); flush(stdout()) > > ### Name: multhist > ### Title: Plot a multiple histogram, as a barplot > ### Aliases: multhist > ### Keywords: hplot > > ### ** Examples > > l <- list(runif(10)*10,1:10,c(1,1,1,1,4,8)) > multhist(l) > > > > cleanEx(); ..nameEx <- "multsymbolbox" > > ### * multsymbolbox > > flush(stderr()); flush(stdout()) > > ### Name: multsymbolbox > ### Title: draw boxes filled with symbols > ### Aliases: multsymbolbox > ### Keywords: aplot > > ### ** Examples > > plot(1:10,1:10,type="n") > multsymbolbox(c(2,4),5,c(4,5),8,tot=c(10,8)) > > > > cleanEx(); ..nameEx <- "pie.labels" > > ### * pie.labels > > flush(stderr()); flush(stdout()) > > ### Name: pie.labels > ### Title: Place labels on a pie chart > ### Aliases: pie.labels > ### Keywords: misc > > ### ** Examples > > pieval<-c(2,4,6,8) > plot(1:5,type="n") > bisect.angles<-floating.pie(3,3,pieval) > pie.labels(3,3,bisect.angles,c("two","four","six","eight")) > > > > cleanEx(); ..nameEx <- "plotCI" > > ### * plotCI > > flush(stderr()); flush(stdout()) > > ### Name: plotCI > ### Title: Plot confidence intervals/error bars > ### Aliases: plotCI > ### Keywords: hplot > > ### ** Examples > > y<-runif(10) > err<-runif(10) > plotCI(1:10,y,err) > plotCI(1:10,y,err,2*err,lwd=2,col="red",scol="blue") > err.x<-runif(10) > err.y<-runif(10) > plotCI(1:10,y,err.y,pt.bg=par("bg"),pch=21) > plotCI(1:10,y,err.x,pt.bg=par("bg"),pch=21,err="x",add=TRUE) > data(warpbreaks) > attach(warpbreaks) > wmeans<-by(breaks,tension,mean) > wsd<-by(breaks,tension,sd) > ## note that barplot() returns the midpoints of the bars, which plotCI > ## uses as x-coordinates > plotCI(barplot(wmeans,col="gray",ylim=c(0,max(wmeans+wsd))),wmeans,wsd,add=TRUE) > ## using labels instead of points > labs<-sample(LETTERS,replace=TRUE,size=10) > plotCI(1:10,y,err,pch=NA,gap=0.02) > text(1:10,y,labs) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "polar.plot" > > ### * polar.plot > > flush(stderr()); flush(stdout()) > > ### Name: polar.plot > ### Title: polar.plot > ### Aliases: polar.plot > ### Keywords: misc > > ### ** Examples > > testlen<-c(rnorm(36)*2+5) > testpos<-seq(0,350,by=10) > polar.plot(testlen,testpos,main="Test Polar Plot") > > > > cleanEx(); ..nameEx <- "radial.plot" > > ### * radial.plot > > flush(stderr()); flush(stdout()) > > ### Name: radial.plot > ### Title: radial.plot > ### Aliases: radial.plot > ### Keywords: misc > > ### ** Examples > > testlen<-rnorm(10)*2+5 > testpos<-seq(0,18*pi/10,length=10) > testlab<-letters[1:10] > radial.plot(testlen,testpos,main="Test Radial Lines",line.col="red",lwd=3) > if(dev.interactive()) par(ask=TRUE) > testlen<-c(sin(seq(0,1.98*pi,length=100))+2+rnorm(100)/10) > testpos<-seq(0,1.98*pi,length=100) > radial.plot(testlen,testpos,rp.type="p",main="Test Polygon",line.col="blue") > radial.plot(testlen,testpos,rp.type="s",main="Test Symbols",point.col="green") > par(ask=FALSE) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "rescale" > > ### * rescale > > flush(stderr()); flush(stdout()) > > ### Name: rescale > ### Title: rescale > ### Aliases: rescale > ### Keywords: misc > > ### ** Examples > > # scale one vector into the range of another > normal.counts<-tabulate(cut(rnorm(100),breaks=seq(-3,3,by=1))) > normal.density<-rescale(dnorm(seq(-3,3,length=100)),range(normal.counts)) > # now plot them > plot(c(-2.5,-1.5,-0.5,0.5,1.5,2.5),normal.counts,type="h") > lines(seq(-3,3,length=100),normal.density) > > > > cleanEx(); ..nameEx <- "show.soil.texture" > > ### * show.soil.texture > > flush(stderr()); flush(stdout()) > > ### Name: show.soil.texture > ### Title: show.soil.texture > ### Aliases: show.soil.texture > ### Keywords: misc > > ### ** Examples > > data(soils) > # first just show the soil triangle > soil.texture(main="Soil Texture Triangle") > # now plot the observations > show.soil.texture(soils,pch=2,col.symbols=2) > > > > cleanEx(); ..nameEx <- "sizeplot" > > ### * sizeplot > > flush(stderr()); flush(stdout()) > > ### Name: sizeplot > ### Title: Plot with repeated symbols by size > ### Aliases: sizeplot > ### Keywords: hplot > > ### ** Examples > > x <- c(0.1,0.1,0.1,0.1,0.1,0.2,0.2,0.2,0.2,0.3,0.3) > y <- c( 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5 ) > plot(x,y) > sizeplot(x,y) > sizeplot(x,y,pch=2) > > > > cleanEx(); ..nameEx <- "soil.texture" > > ### * soil.texture > > flush(stderr()); flush(stdout()) > > ### Name: soil.texture > ### Title: soil.texture > ### Aliases: soil.texture > ### Keywords: misc > > ### ** Examples > > data(soils) > soil.texture() > if(dev.interactive()) par(ask=TRUE) > main.title<-"DEFAULT" > soil.texture(soils,main=main.title,pch=2) > main.title<-"LINES AND NAMES" > soil.texture(soils,main=main.title,show.lines=TRUE,show.names=TRUE, + pch=3) > main.title<- "GRID AND LEGEND" > soil.texture(soils[1:6,],main=main.title,show.grid=TRUE,pch=4, + col.symbols=1:6,show.legend=TRUE) > if(dev.interactive()) par(ask=FALSE) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "spread.labels" > > ### * spread.labels > > flush(stderr()); flush(stdout()) > > ### Name: spread.labels > ### Title: Spread labels for irregularly spaced values > ### Aliases: spread.labels > ### Keywords: misc > > ### ** Examples > > x<-rnorm(10)/10 > y<-sort(rnorm(10)) > plot(x,y,xlim=c(-1,1),type="p") > nums<-c("one","two","three","four","five","six","seven","eight","nine","ten") > spread.labels(x,y,nums,0.5) > > > > cleanEx(); ..nameEx <- "staxlab" > > ### * staxlab > > flush(stderr()); flush(stdout()) > > ### Name: staxlab > ### Title: Place staggered labels on an axis > ### Aliases: staxlab > ### Keywords: misc > > ### ** Examples > > plot(1:10,axes=FALSE) > box() > nums<-c("one","two","three","four","five","six","seven","eight","nine","ten") > staxlab(1,1:10,nums) > > > > cleanEx(); ..nameEx <- "symbolbox" > > ### * symbolbox > > flush(stderr()); flush(stdout()) > > ### Name: symbolbox > ### Title: Draw a box filled with symbols > ### Aliases: symbolbox > ### Keywords: aplot > > ### ** Examples > > plot(1:10,1:10,type="n") > symbolbox(2,5,3,7,tot=20) symbolbox: 2 5 3 7 20 symbolbox: 1.023962 1.219695 4 5 4 5 20 > symbolbox(6,2,10,6,tot=50,fg="blue",bg="magenta") symbolbox: 6 2 10 6 50 symbolbox: 4.095849 2.439390 9 6 9 6 50 > > > > cleanEx(); ..nameEx <- "textbox" > > ### * textbox > > flush(stderr()); flush(stdout()) > > ### Name: textbox > ### Title: Add text box > ### Aliases: textbox > ### Keywords: aplot > > ### ** Examples > > plot.new() > textbox(c(0,0.2),1,c("many words","more words","why not?", + "keep going",rep("and going",10))) > > > > cleanEx(); ..nameEx <- "thigmophobe" > > ### * thigmophobe > > flush(stderr()); flush(stdout()) > > ### Name: thigmophobe > ### Title: thigmophobe > ### Aliases: thigmophobe > ### Keywords: misc > > ### ** Examples > > x<-rnorm(10) > y<-rnorm(10) > thigmophobe(x,y) [1] 3 3 1 1 3 3 1 4 2 2 > > > > cleanEx(); ..nameEx <- "thigmophobe.labels" > > ### * thigmophobe.labels > > flush(stderr()); flush(stdout()) > > ### Name: thigmophobe.labels > ### Title: thigmophobe.labels > ### Aliases: thigmophobe.labels > ### Keywords: misc > > ### ** Examples > > x<-rnorm(20) > y<-rnorm(20) > xlim<-range(x) > xspace<-(xlim[2]-xlim[1])/20 > xlim<-c(xlim[1]-xspace,xlim[2]+xspace) > ylim<-range(y) > yspace<-(ylim[2]-ylim[1])/20 > ylim<-c(ylim[1]-yspace,ylim[2]+yspace) > plotlabels<- + c("one","two","three","four","five","six","seven","eight","nine","ten", + "eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen", + "eighteen","nineteen","twenty") > plot(x=x,y=y,xlim=xlim,ylim=ylim,main="Test thigmophobe.labels") > # skip the almost invisible yellow label > thigmophobe.labels(x,y,plotlabels,col=c(2:6,8:12)) > > > > ### *