RDX2 X  g1.1 source function(device=""){ & if(device!="")hardcopy(width=2.25, 6 height=2.25, device=device) G oldpar <- par(mar = c(4.1,4.1,1.1,1.1), pty="s", mgp=c(2.5,0.75,0))  on.exit(par(oldpar)) + Year <- c(1800, 1850, 1900, 1950, 2000) ' Carbon <- c(8, 54, 534, 1630, 6611)  plot(Carbon ~ Year, pch=16)  if(device!="")dev.off()  }ў§ device ў { if !=џ ў hardcopy width@ height@џџўў <- oldpar par mar c@ffffff@ffffff?ё™™™™™š?ё™™™™™šў pty s mgpџ@?шўўў on.exit џ џўў џ Yearџ@œ @œш@А@žx@Ÿ@ўў џ Carbonџ@ @K@€А@™x@Йгўў plot ~џџў pch@0ўџџџ ў dev.offўўў g1.2џ function(device=""){ @ if(device!="")hardcopy(device=device, width=2.3, height=2.3) > oldpar <- par(mar = c(4.1,4.1,1.1,1.1), mgp=c(2.5,0.75,0), ! cex.axis=0.875)  on.exit(par(oldpar))  attach(primates) % plot(x=Bodywt, y=Brainwt, pch=16, ; xlab="Body weight (kg)", ylab="Brain weight (g)", ' xlim=c(0,300), ylim=c(0,1500))  chw <- par()$cxy[1]  chh <- par()$cxy[2] 6 text(x=Bodywt, y=Brainwt+c(-.125,0,0,.125,0)*chh, + labels=row.names(primates), pos=4)  detach(primates)  if(device!="")dev.off()  }ў§$џ ўџџџџ ўџџџџ@ffffff џ@ffffffўў џ џ џ џџ@ffffff@ffffff?ё™™™™™š?ё™™™™™šўџџ@?шў cex.axis?ьўўџ џ џўў attach primatesўџ x Bodywt y Brainwtџ@0 xlab Body weight (kg) ylab Brain weight (g) xlimџ@rРў ylimџ@—pўў џ chw [ $ џў cxyў?№ўў џ chh%џ&џ џў cxyў@ўў textџџџ +џ *џ -?Рў?Рў'џўў labels row.namesџў pos@ў detachџўџџџ ўџўўў g1.3џ function(device=""){ K if(device!="")hardcopy(width=1.6, height=1, device=device, pointsize=7) - oldpar <- par(mar=rep(0,4), mgp=rep(0,3))  on.exit(par(oldpar)) @ ## Start new plot; draw circle: center at (0,0), radius=0.95 I symbols(0, 0, circles=0.95, bg="gray", xlim=c(-1,2.25), ylim=c(-1,1),  bty="n", K inches=FALSE) # inches=FALSE: radius is in x-axis units D text(1.75, 0, expression("Area" == pi*phantom("'")*italic(r)^2)) F ## Character strings are allowed as 'variables' in 'expressions' N arrows(0, 0, -0.95, 0, length=.05, code=3) # code=3: arrows at both ends 7 text(-0.45, -strheight("R"), expression(italic(r)))  if(device!="")dev.off()  }ў§$џ ўџџџџ ўџџ?љ™™™™™š џ?№џџ pointsize@ўў џ џ џ џ rep@ўџ2џ@ўўўџ џ џўў symbols circles?юffffff bg gray"џџ+џ?№ў@ў#џџ+џ?№ў?№ў bty n inches ў(џ?ќ expression == Area*џ*џ pi phantom 'ўў ^ italic rў@ўўўўў arrows+џ?юffffffў length?Љ™™™™™š code@ў(џ+џ?мЬЬЬЬЬЭў+џ strheight Rўў8џ=џ>џўўўџџџ ўџўўў g1.4џ >function(width=4.0, height=2.25, pointsize=c(7,5), device=""){ 7 if(device!="") hardcopy(width=width, height=height, 9 color=F, pointsize=pointsize, 8 trellis=TRUE, device=device) G trellis.par.set(list(superpose.symbol=list(pch=c(4,1), col=c(1,1)), ( superpose.line= ( list(lty=1:2))) 4 ## Specify after opening any new graphics device + here <- ais$sport %in% c("Row", "Swim") E gph <- xyplot(ht ~ wt | sport, groups=sex, subset=here, data=ais, K auto.key=list(columns=2), aspect=1, scales=list(tck=0.5)) & print(trellis.par.get("fontsize")) + print(gph) = ## The parameter "span" controls the extent of smoothing.  if(device!="")dev.off()  }ў§џ@ џ@1џџ@@ў$џ ўџџџџ ўџџџ џ џ color F1џ1џ trellis џџўў trellis.par.set list superpose.symbolHџџџ@?№ў colџ?№?№ўў superpose.lineHџ lty :?№@ўўўў џ here %in%&џ ais sportўџ Row Swimўўў џ gph xyplotџ ht | wt sportўў groups sex subsetNџ dataPџ auto.keyHџ columns@ў aspect?№ scalesHџ tck?рўўў print trellis.par.get fontsizeўў`џQџўџџџ ўџўўў gdumpџ 7function(fnam=NULL, prefix="~/r-book/ed2/figures/figs",  splitchar="/ch"){  if(is.null(fnam)){  path <- getwd() 7 pathtag <- strsplit(path, "/ch", fixed=TRUE)[[1]] 5 fnam <- paste(prefix, pathtag[length(pathtag)], ! ".R", sep="")  } - else fnam <- paste(prefix, fnam, sep="/") H objnames <- c(objects(pattern="^g", envir=sys.frame(0)), "hardcopy") & cat("\nDump to file:", fnam, "\n")  print(objnames)  dump(objnames, fnam)  }ў§ fnamў prefix ~/r-book/ed2/figures/figs splitchar /chўџџ is.nullcџўџ џ path getwdўў џ pathtag [[ strsplitgџ /ch fixed ў?№ўў џcџ pastedџ%џiџ@џiџўў .R sep ўўў џcџmџdџcџnџ /ўўў џ objnamesџ objects pattern ^g envir sys.frameўў hardcopyўў cat  Dump to file:cџ  ў`џoџў dumpoџcџўў gsaveџ 7function(fnam=NULL, prefix="~/r-book/ed2/figures/figs", K splitchar="/ch", xtras=c("hardcopy","renum.fun","renum.files")){  if(is.null(fnam)){  path <- getwd() 7 pathtag <- strsplit(path, "/ch", fixed=TRUE)[[1]] 5 fnam <- paste(prefix, pathtag[length(pathtag)], % ".RData", sep="")  } - else fnam <- paste(prefix, fnam, sep="/") C objnames <- c(objects(pattern="^g", envir=sys.frame(0)), xtras) & cat("\nDump to file:", fnam, "\n")  print(objnames) " save(list=objnames, file=fnam)  }ў§cџўdџ ~/r-book/ed2/figures/figseџ /ch xtrasџ hardcopy renum.fun renum.filesўўџџfџcџўџ џgџhџўў џiџjџkџgџ /chlџ ў?№ўў џcџmџdџ%џiџ@џiџўў .RDatanџ ўўў џcџmџdџcџnџ /ўўў џoџџpџqџ ^grџsџўўwџўўtџ  Dump to file:cџ  ў`џoџў saveHџoџ filecџўўџџ4 =function(width=3.75, height=3.75, color=FALSE, trellis=FALSE, < device=c("","pdf","ps"), path=getwd(), file=NULL, D format=c("nn-nn", "name"), split="\\.", pointsize=c(8,4),  fonts=NULL,  horiz=FALSE, ...){ ) if(!trellis)pointsize <- pointsize[1]  funtxt <- sys.call(1) B nam <- strsplit(as.character(funtxt), "(", fixed=TRUE)[[1]][1] 3 suffix <- switch(device, ps=".eps", pdf=".pdf") N if(is.character(path) & nchar(path)>1 & substring(path, nchar(path))!="/") & path <- paste(path, "/", sep="") - if(is.null(file)) if(format[1]=="nn-nn"){ C if(!is.null(split))dotsplit <- strsplit(nam, split)[[1]] else  dotsplit <- nam 8 if(length(dotsplit)==1)dotsplit <- c("", dotsplit) E nn2 <- paste(if(nchar(dotsplit[2])==1)"0" else "", dotsplit[2],  sep="")  if(nchar(dotsplit[1])>0){ O numstart <- which(unlist(strsplit(dotsplit[1], "")) %in% paste(0:9))[1] / nn1 <- substring(dotsplit[1], numstart) G nn1 <- paste(if(nchar(nn1) == 1) "0" else "", nn1, "-", sep="")  } else nn1 <- "" % file <- paste(nn1, nn2, sep="")  } else file <- nam L if(nchar(file)>4 & substring(file, nchar(file)-nchar(suffix)+1)==suffix)  suffix <- "" - file <- paste(path, file, suffix, sep="") : print(paste("Output will be directed to file:", file))  dev.out <- device[1] 6 dev.fun <- switch(dev.out, pdf=pdf, ps=postscript)  if(trellis){  library(lattice)  if(device=="ps") 1 trellis.device(file=file, device=dev.fun, ? color = color, horiz=horiz, fonts=fonts, < width=width, height=height, ...) else < trellis.device(file=file, device=dev.fun, fonts=fonts, D color = color, width=width, height=height, ...) R trellis.par.set(list(fontsize=list(text=pointsize[1], points=pointsize[2]))) } else  if (dev.out!=""){  print(c(width, height))  if(device=="ps") F dev.fun(file=file, paper="special", horiz=horiz, fonts=fonts, M width=width, height=height, pointsize=pointsize[1], ...) else 6 dev.fun(file=file, paper="special", fonts=fonts, L width=width, height=height, pointsize=pointsize[1], ...)  } D if(trellis)trellis.par.set(list(fontsize=list(text=pointsize[1], < points=pointsize[2])))  }ў§џ@ џ@Dџ Fџ џџ  pdf psўgџhџўyџў formatџ nn-nn nameў split \.1џџ@ @ў fontsў horiz  ...ћў srcref  ) srcfileђ encoding native.enc timestampAбрТŽ class POSIXt POSIXctў filename /tmp/johnm.hardcopy.R wd /Users/johnm/r/ch1ўў„џ srcfileў„џ srcrefў €џџ„џ srcrefў   B€џџ„џ srcrefў   3€џџ„џ srcrefў   &€џџ„џ srcrefў  €џџ„џ srcrefў €џџ„џ srcrefў -€џџ„џ srcrefў :€џџ„џ srcrefў €џџ„џ srcrefў 6€џџ„џ srcrefў  2€џџ„џ srcrefў 34<€џџ„џ srcrefў€џџўџџ !Fџў џ1џ%џ1џ?№ўўў џ funtxt sys.call?№ўў џ nam%џjџkџ as.characterˆџў (lџ ў?№ў?№ўў џ suffix switchџ ps .eps pdf .pdfўўџ &џ is.charactergџў > nchargџў?№ўўџ substringgџ“џgџўў /ўў џgџmџgџ /nџ ўўўџfџyџўџ9џ%џzџ?№ў nn-nnўџ €џџ„џ srcrefў 8€џџ„џ srcrefў €џџ„џ srcrefў €џџ„џ srcrefў %€џџ„џ srcrefў€џџўџџ‡џfџ{џўў џ dotsplitjџkџŠџ{џў?№ўў џ•џŠџўўџ9џ@џ•џў?№ў џ•џџ •џўўў џ nn2mџџ9џ“џ%џ•џ@ўў?№ў 0 ў%џ•џ@ўnџ ўўџ’џ“џ%џ•џ?№ўўўџ  O€џџ„џ srcrefў  /€џџ„џ srcrefў  G€џџ„џ srcrefў€џџўџ џ numstart%џ whichOџ unlistkџ%џ•џ?№ў ўўmџMџ@"ўўўў?№ўў џ nn1”џ%џ•џ?№ў—џўў џšџmџџ9џ“џšџў?№ў 0 ўšџ -nџ ўўў џšџ ўў џyџmџšџ–џnџ ўўў џyџŠџўўўџџ’џ“џyџў@ў9џ”џyџ)џ+џ“џyџў“џŒџўў?№ўўŒџўў џŒџ ўў џyџmџgџyџŒџnџ ўў`џmџ Output will be directed to file:yџўў џ dev.out%џџ?№ўў џ dev.funџ›џџџŽџ postscriptўўџFџџ !!€џџ„џ srcrefў "'D€џџ„џ srcrefў ))R€џџ„џ srcrefў€џџўџ library latticeўџ9џџ psў trellis.deviceyџyџџœџDџDџ}џ}џ|џ|џџџ џ џ~џў џyџyџџœџ|џ|џDџDџџџ џ џ~џўўGџHџ fontsizeHџ(џ%џ1џ?№ў points%џ1џ@ўўўўўџџ›џ ўџ ,,€џџ„џ srcrefў -1F€џџ„џ srcrefў€џџўџ`џџџ џўўџ9џџ psўœџyџyџ paper special}џ}џ|џ|џџџ џ џ1џ%џ1џ?№ў~џўœџyџyџЃџ special|џ|џџџ џ џ1џ%џ1џ?№ў~џўўўўўџFџGџHџЁџHџ(џ%џ1џ?№ўЂџ%џ1џ@ўўўўўў renum.funџ Dfunction(from.prefix="g", to.prefix="g",from=20:7, to=21:8, doit=F){  path <- getwd() 5 pathtag <- strsplit(path, "/ch", fixed=TRUE)[[1]] & endbit <- pathtag[length(pathtag)] 5 from.prefix <- paste(from.prefix, endbit, sep="") 1 to.prefix <- paste(to.prefix, endbit, sep="")  for(i in 1:length(to)) M {txt<-paste(to.prefix,".",to[i]," <- ", from.prefix,".",from[i],sep="") 7 if(doit)eval(parse(text=txt),envir=sys.frame(0))  print(txt)  }  }ў§ from.prefix g to.prefix g$ fromMџ@4@ў$ toMџ@5@ ў$ doitEџўџ џgџhџўў џiџjџkџgџ /chlџ ў?№ўў џ endbit%џiџ@џiџўўў џЅџmџЅџЊџnџ ўў џІџmџІџЊџnџ ўў for iMџ?№@џЈџўўџ џ txtmџІџ .%џЈџЌџў  <- Ѕџ .%џЇџЌџўnџ ўўџЉџ eval parse(џ­џўrџsџўўў`џ­џўўўў renum.filesџ Hfunction(from.prefix="~/r-book/ed2/Art/", to.prefix="~/r-book/ed2/Art/", ' from=20:7, to=21:8, doit=F){  path <- getwd() 5 pathtag <- strsplit(path, "/ch", fixed=TRUE)[[1]] & endbit <- pathtag[length(pathtag)] 2 if(nchar(endbit)==2)chap <- paste(endbit) else $ chap <- paste("0",endbit,sep="") 8 from.prefix <- paste(from.prefix, chap, "-", sep="") 4 to.prefix <- paste(to.prefix, chap, "-", sep="")  for(i in 1:length(from)){ 8 if (from[i]<=9) ltext <- paste("0",from[i],sep="") " else ltext <- paste(from[i]) 4 if (to[i]<=9) rtext <- paste("0",to[i],sep="") , else rtext <- paste(to[i]) 8 txt<-paste("mv ", from.prefix, ltext, ".eps", " ", 2 to.prefix, rtext, ".eps", sep="") ; backup<-paste("cp ", from.prefix, ltext, ".eps", " ", & "archive", sep="")  if(doit)system(backup)  if(doit)system(txt)  print(backup)  print(txt)  }  }ў§Ѕџ ~/r-book/ed2/Art/Іџ ~/r-book/ed2/Art/$ЇџMџ@4@ў$ЈџMџ@5@ ў$ЉџEџўџ џgџhџўў џiџjџkџgџ /chlџ ў?№ўў џЊџ%џiџ@џiџўўўџ9џ“џЊџў@ў џ chapmџЊџўў џБџmџ 0Њџnџ ўўў џЅџmџЅџБџ -nџ ўў џІџmџІџБџ -nџ ўўЋџЌџMџ?№@џЇџўўџџ <=%џЇџЌџў@"ў џ ltextmџ 0%џЇџЌџўnџ ўў џГџmџ%џЇџЌџўўўўџВџ%џЈџЌџў@"ў џ rtextmџ 0%џЈџЌџўnџ ўў џДџmџ%џЈџЌџўўўў џ­џmџ mv ЅџГџ .eps  ІџДџ .epsnџ ўў џ backupmџ cp ЅџГџ .eps   archivenџ ўўџЉџ systemЕџўўџЉџЖџ­џўў`џЕџў`џ­џўўўўў