### R code from vignette source 'naming.Rnw' ################################################### ### code chunk number 1: naming.Rnw:49-51 ################################################### options(continue=" ") library(grid) ################################################### ### code chunk number 2: naming.Rnw:104-105 ################################################### library(lattice) ################################################### ### code chunk number 3: latticesrc (eval = FALSE) ################################################### ## barchart(yield ~ variety | site, data = barley, ## groups = year, layout = c(1,6), stack = TRUE, ## ylab = "Barley Yield (bushels/acre)", ## scales = list(x = list(rot = 45))) ################################################### ### code chunk number 4: lattice ################################################### print( barchart(yield ~ variety | site, data = barley, groups = year, layout = c(1,6), stack = TRUE, ylab = "Barley Yield (bushels/acre)", scales = list(x = list(rot = 45))) ) ################################################### ### code chunk number 5: trellispars ################################################### trellispars <- trellis.par.get() pars <- unlist(mapply(function(name, par) { c(name, paste(" ", names(par))) }, names(trellispars), trellispars)) font <- unlist(mapply(function(name, par) { c("bold", rep("plain", max(1, length(par)))) }, names(trellispars), trellispars)) nrow <- 40 ncol <- length(pars) %/% nrow + 1 grid.newpage() pushViewport(viewport(layout=grid.layout(1, ncol), gp=gpar(cex=1))) for (j in 1:ncol) { start <- (j - 1)*nrow + 1 end <- min(j*nrow, length(pars)) pushViewport(viewport(layout.pos.row=1, layout.pos.col=j)) grid.text(pars[start:end], x=0, y=unit(1, "npc") - unit(1:(end - start + 1), "lines"), just=c("left"), gp=gpar(fontface=font[start:end], fontfamily="mono")) popViewport() } popViewport() ################################################### ### code chunk number 6: metafor ################################################### library(metafor) yi<-c(-0.1, 0.2, 0.3, 0.4) sei<-c(0.4, 0.2, 0.6, 0.1) vi<-sei studi<-c("A", "B", "C", "D") eventi.c<-c(10, 5, 7, 6) n.c<-c(11, 34, 25, 20) eventi.a<-c(2, 7, 6, 5) n.a<-c(11, 35, 25, 15) dfs<-rma(yi, vi, method="DL") dfs forest.rma(dfs, slab=studi, xlim=c(-15, 10), ilab=cbind(eventi.c, n.c, eventi.a, n.a), ilab.xpos=c(-9.5, -8, -6, -4.5), cex=1.2, at=c(-2, -1, 0, 1, 2), xlab="Hazard Ratio (log scale)", mlab="Random Effects Model", efac=5, col="red", border="red") text(-10, -1.3, paste("Heterogeneity: I-squared=", paste(paste(round(dfs$I2, 2), "%", sep=""), paste("p", round(dfs$QEp, 4), sep="="), sep=", "), sep=""), font=4, cex=1.2) op<-par(cex=1.2, font=2, oma=c(0.5, 0.5, 0.5, 0.5), mar=c(0.5, 0.5, 0.5, 0.5)) text(x=c(-9.5, -8, -6, -4.5), 6, c("Events", "N", "Events", "N"), cex=1.2 ) text(c(-8.7, -5.5, 8), 6.5, c("S", "A", "Log")) text(-15, 6, "Trials", pos=4) text(10, 6, "Hazard Ratio [95% CI]", pos=2) par(op) ################################################### ### code chunk number 7: xyplotsrc ################################################### xyplot(1 ~ 1) ################################################### ### code chunk number 8: xyplot ################################################### pushViewport(viewport(y=1, height=.6, just="top")) print( xyplot(1 ~ 1) , prefix="plot_01", newpage=FALSE) ################################################### ### code chunk number 9: gridlssrc (eval = FALSE) ################################################### ## grid.ls() ################################################### ### code chunk number 10: gridls ################################################### grid.newpage() pushViewport(viewport(y=1, height=.6, just="top")) print( xyplot(1 ~ 1) , prefix="plot_01", newpage=FALSE) grid.ls() ################################################### ### code chunk number 11: editsrc ################################################### grid.edit("plot_01.xlab", label="I pity the fool", gp=gpar(fontface="bold.italic")) ################################################### ### code chunk number 12: edit ################################################### pdf("naming-edit-%d.pdf", width=3, height=5, onefile=FALSE) pushViewport(viewport(y=1, height=.6, just="top")) print( xyplot(1 ~ 1) , prefix="plot_01", newpage=FALSE) grid.edit("plot_01.xlab", label="I pity the fool", gp=gpar(fontface="bold.italic")) dev.off() ################################################### ### code chunk number 13: naming.Rnw:434-435 (eval = FALSE) ################################################### ## barchart(yield ~ variety | site, data = barley, ## groups = year, layout = c(1,6), stack = TRUE, ## ylab = "Barley Yield (bushels/acre)", ## scales = list(x = list(rot = 45))) ################################################### ### code chunk number 14: lowlevelsrc1 (eval = FALSE) ################################################### ## grid.edit("barchart.pos.6.rect", ## grep=TRUE, global=TRUE, ## gp=gpar(lwd=2)) ################################################### ### code chunk number 15: lowlevelsrc2 (eval = FALSE) ################################################### ## fontface <- rep("plain", 10) ## fontface[6] <- "bold" ## cex <- rep(.8, 6) ## cex[6] <- 1 ## ## grid.edit("ticklabels.bottom.panel", grep=TRUE, ## gp=gpar(fontface=fontface, cex=cex)) ################################################### ### code chunk number 16: lowlevel ################################################### pdf("naming-lowlevel-%d.pdf", onefile=FALSE, width=6, height=6) print( barchart(yield ~ variety | site, data = barley, groups = year, layout = c(1,6), stack = TRUE, ylab = "Barley Yield (bushels/acre)", scales = list(x = list(rot = 45))) ) grid.edit("barchart.pos.6.rect", grep=TRUE, global=TRUE, gp=gpar(lwd=2)) fontface <- rep("plain", 10) fontface[6] <- "bold" cex <- rep(.8, 6) cex[6] <- 1 grid.edit("ticklabels.bottom.panel", grep=TRUE, gp=gpar(fontface=fontface, cex=cex)) dev.off() ################################################### ### code chunk number 17: showgrob ################################################### pdf("naming-showgrob-%d.pdf", onefile=FALSE) print( barchart(yield ~ variety | site, data = barley, groups = year, layout = c(1,6), stack = TRUE, ylab = "Barley Yield (bushels/acre)", scales = list(x = list(rot = 45))) ) grid.remove("background", grep=TRUE) grid.remove("border", grep=TRUE, global=TRUE) grid.remove("textr", grep=TRUE, global=TRUE) showGrob(gp=gpar(col="black", fill="pink")) dev.off() ################################################### ### code chunk number 18: naming.Rnw:578-580 ################################################### library(ggplot2) library(gridSVG) ################################################### ### code chunk number 19: naming.Rnw:583-585 ################################################### df <- data.frame(time=as.numeric(time(Nile)), flow=as.numeric(Nile)) ################################################### ### code chunk number 20: ggplot2 ################################################### thePlot <- ggplot(df, aes(x=time, y=flow)) + geom_line() pushViewport(viewport(layout=grid.layout(2, 1, heights=c(4, 1)))) pushViewport(viewport(layout.pos.row=1, name="topvp")) print(thePlot, newpage=FALSE) upViewport() pushViewport(viewport(layout.pos.row=2, name="bottomvp")) print(thePlot, newpage=FALSE) upViewport(2) ################################################### ### code chunk number 21: ggplotmodsrc1 (eval = FALSE) ################################################### ## downViewport("bottomvp") ## downViewport("panel-3-3") ## grid.rect(x=0, width=0.25, just="left", ## name="thumb", ## gp=gpar(col=rgb(0,0,1,.5), fill=rgb(0,0,1,.2))) ################################################### ### code chunk number 22: ggplotmodsrc2 (eval = FALSE) ################################################### ## grid.garnish("thumb", ## onmousedown="thumbDown(evt)") ################################################### ### code chunk number 23: ggplotmodsrc3 (eval = FALSE) ################################################### ## grid.script(filename="thumb.js") ################################################### ### code chunk number 24: ggplotmod ################################################### thePlot <- ggplot(df, aes(x=time, y=flow)) + geom_line() pushViewport(viewport(layout=grid.layout(2, 1, heights=c(4, 1)))) pushViewport(viewport(layout.pos.row=1, name="topvp")) print(thePlot, newpage=FALSE) upViewport() pushViewport(viewport(layout.pos.row=2, name="bottomvp")) print(thePlot, newpage=FALSE) upViewport(2) downViewport("bottomvp") downViewport("panel-3-3") grid.rect(x=0, width=0.25, just="left", name="thumb", gp=gpar(col=rgb(0,0,1,.5), fill=rgb(0,0,1,.2))) grid.garnish("thumb", onmousedown="thumbDown(evt)") grid.script(filename="thumb.js") ################################################### ### code chunk number 25: naming.Rnw:667-668 (eval = FALSE) ################################################### ## gridToSVG()