S Graphics
Paul Murrell
paul@stat.auckland.ac.nz
The University of Auckland
S Graphics – p.1/38
S Graphics Paul Murrell paul@stat.auckland.ac.nz The University of - - PowerPoint PPT Presentation
S Graphics Paul Murrell paul@stat.auckland.ac.nz The University of Auckland S Graphics p.1/38 Overview Things that are covered Command-line Graphics Customising Traditional S Graphics Customising Traditional Trellis Graphics Things that
Paul Murrell
paul@stat.auckland.ac.nz
The University of Auckland
S Graphics – p.1/38
S Graphics – p.2/38
S Graphics – p.3/38
Tim Hoar, Eric Gilleland, Doug Nychka
S Graphics – p.4/38
The Bioconductor Project
S Graphics – p.5/38
Corey A. Moffet, Texas Tech University
S Graphics – p.6/38
David Scott, The University of Auckland
S Graphics – p.7/38
S Graphics – p.8/38
Figure Region
Outer margin 1 Outer margin 2 Outer margin 3 Outer margin 4
S Graphics – p.9/38
Figure 1 Figure 2
S Graphics – p.10/38
Plot Region
Figure Margin 1 Figure Margin 2 Figure Margin 3 Figure Margin 4 Outer margin 1 Outer margin 2 Outer margin 3 Outer margin 4
S Graphics – p.11/38
Minimum x value Maximum x value Minimum y value Maximum y value The location (xi, yi) xi yi
S Graphics – p.12/38
Figure Margin 1 11 0 lines 3 lines Figure Margin 2 11 0 lines 3 lines
S Graphics – p.13/38
11 Current Plot Outer Margin 1 11 l i n e s 3 l i n e s 11 11 Current Plot Outer Margin 1 1 l i n e s 3 l i n e s
S Graphics – p.14/38
S Graphics – p.15/38
S Graphics – p.16/38
> midpts <- barplot(1:5, density = -1) > text(midpts, 0.1, 1:5, srt = 90, adj = 0)
2 4 6 8 10 1 2 3 4 5 6 7 8 9 10
S Graphics – p.17/38
> plot(0:1, 1:2) > par("usr") [1] -0.04 1.04 0.96 2.04 > par("uin") [1] 6.603704 4.659259
> E.intervals <- co.intervals(ethanol$E, 16, 0.25) > coplot(NOx ˜ C | E, given.values = E.intervals, data = ethanol, + panel = function(x, y, col, pch)
points(x, y); + axis(1, tck=1, lty=2, labels=F); + axis(2, tck=1, lty=2, labels=F)
✁)
S Graphics – p.18/38
1 2 3 4 8 10 14 18 8 10 14 18 1 2 3 4 1 2 3 4 8 10 14 18 8 10 14 18 1 2 3 4
C NOx
0.6 0.7 0.8 0.9 1.0 1.1 1.2
Given : E
S Graphics – p.19/38
2 4 6 8 10 2 4 6 8 10 1:10
S Graphics – p.20/38
> par(omi=rep(0, 4), mar=c(5.1, 4.1, 4.1, 2.1), mfrow=c(1, 1)) > plot(0, type="n", xlim=c(0, 10), ylim=c(0,10), + axes=F, xlab="", ylab="")
> par(col=1, lty=1, lwd=1, cex=1, srt=0) > points(1:10)
> box() > axis(1) > axis(2) > mtext("1:10", side=2, line=3)
S Graphics – p.21/38
2 4 6 8 10 12 14 Group 1 Group 2 Group 3 Group 4
S Graphics – p.22/38
par(fig=c(0, 0.8, 0, 1), mar=c(4, 4, 4, 2))
barplot(matrix(sample(1:4, 16, replace=T), ncol=4), angle=45, density=1:4*10, col=1)
par(new=T) par(fig=c(0.8, 1, 0, 1), mar=c(4, 0, 4, 2)) plot(0, xlim=c(0, 1), ylim=c(0, 5), axes=F, xlab="", ylab="", type="n")
S Graphics – p.23/38
size <- par("cxy")/par("cin")*.5
box(lty=2) for (i in 1:4) polygon(c(0.5 - size[1]/2, 0.5 - size[1]/2, 0.5 + size[1]/2, 0.5 + size[1]/2), c(i, i + size[2], i + size[2], i), angle=45, density=i*10) text(0.5, i-0.2, paste("Group", i))
S Graphics – p.24/38
S Graphics – p.25/38
x y Plot Region −2 −1 1 2 −2 −1 1 2 Strip Region Plot Region Strip Region Plot Region Strip Region Plot Region −2 −1 1 2 Strip Region −2 −1 1 2 S Graphics – p.26/38
xyplot(y ˜ x | g, layout=c(2, 4))
x y −2 2 4 −2 −1 1 2 g g g −2 2 4 g −2 2 4 g g g −2 2 4 g −2 −1 1 2 S Graphics – p.27/38
xyplot(y ˜ x | g, aspect=0.5)
x y −2 −1 1 2 −2 2 4 g g g −2 −1 1 2 g −2 −1 1 2 g g g −2 −1 1 2 g −2 2 4 S Graphics – p.28/38
myplot <- xyplot(y ˜ x | g) print.trellis(myplot, position=c(0, 0.5, 1, 1))
x y −1 1 2 −3 −2 −1 1 2 g g −3 −2 −1 1 2 g g g −1 1 2 g −1 1 2 g g −3 −2 −1 1 2 S Graphics – p.29/38
xyplot(y ˜ x | g, scales=list(limits=c(-4, 4)))
x y −2 −1 1 2 −3 −2 −1 1 2 3 g g −3 −2 −1 1 2 3 g g g −2 −1 1 2 g −2 −1 1 2 g g −3 −2 −1 1 2 3 S Graphics – p.30/38
xyplot(y ˜ x | g, panel=function(x, y, ...)
abline(0, 0)
✁)
S Graphics – p.31/38
x y −2 −1 1 2 −2 −1 1 2 g g −2 −1 1 2 g g g −2 −1 1 2 g −2 −1 1 2 g g −2 −1 1 2 S Graphics – p.32/38
xyplot(y ˜ x | g, strip=function(which.given, which.panel, var.name, factor.levels, shingle.intervals, par.strip.text, strip.names, style)
paste("Variable ", which.given, ": Level ", which.panel[which.given], sep=""), adj=0)
✁)
S Graphics – p.33/38
x y −2 −1 1 2 −2 −1 1 2 Variable 1: Level 1 Variable 1: Level 2 −2 −1 1 2 Variable 1: Level 3 Variable 1: Level 4 Variable 1: Level 5 −2 −1 1 2 Variable 1: Level 6 −2 −1 1 2 Variable 1: Level 7 Variable 1: Level 8 −2 −1 1 2 S Graphics – p.34/38
xyplot(y ˜x|g, prepanel=function(x ,y)
ylim=range(y)+c(-1,1))
✁)
S Graphics – p.35/38
x y −2 2 −4 −2 2 g g −4 −2 2 g g g −2 2 g −2 2 g g −4 −2 2 S Graphics – p.36/38
> xyplot(y ˜ x | g, pch=16)
> trellis.par.get("plot.symbol") $cex: [1] 0.8 $col: [1] 2 $font: [1] 1 $pch: [1] 1 > ps <- trellis.par.get("plot.symbol") > ps$pch=16 > trellis.par.set("plot.symbol", ps)
S Graphics – p.37/38
S Graphics – p.38/38