Lecture 5 advanced multipanel plots Trevor A. Branch [email protected] Beautiful graphics in R, FISH554...

24
Lecture 5 advanced multipanel plots Trevor A. Branch [email protected] Beautiful graphics in R, FISH554 SAFS, University of Washington

Transcript of Lecture 5 advanced multipanel plots Trevor A. Branch [email protected] Beautiful graphics in R, FISH554...

Page 1: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Lecture 5 advanced multipanel plots

Trevor A. [email protected]

Beautiful graphics in R, FISH554SAFS, University of Washington

Page 2: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Other visualization courses at UWINFO 424 Information Visualization and Aesthetics (Ostergren, Fall

http://courses.washington.edu/info424/)INFX 598E Information Visualization for Information Professionals (Ostergren,

summer https://canvas.uw.edu/courses/891359)HCDE 411 Information Visualization (Aragon, uses Tableau, http

://faculty.washington.edu/aragon/classes/hcde411/w13/)HCDE 508 Visual Media (Ostergren, http://www.hcde.washington.edu/courses)HCDE 511 Information Visualization (Aragon, http://

www.washington.edu/students/icd/S/hcde/511aragon.html)CSE 512 Information Visualization (Heer, uses D3, HTML, R, etc.

http://courses.cs.washington.edu/courses/cse512/14wi/)DESIGN 478 Information Design (Cheng, limited to Design students, http://

www.washington.edu/students/crscat/design.html)

Note: HCDE=Human Centered Design & Engineering, INFO=Information School, CSE=Computer Science & Engineering, DESIGN=School of Art, division of Design

Page 3: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Five multipanel methods in base R

• Methods cannot be combined with each other• par(mfrow) or par(mfcol)• layout(mat, widths, widths)• par(fig)• par(plt)• split.screen(figs)

Page 4: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

par(mfrow)Every figure is the same size

Page 5: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.
Page 6: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

layout(mat)Figures must be placed on a grid system; widths and heights can be adjusted; figures can occupy more than one grid rectangle; squares can be left blank

Page 7: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Branch et al. (2011) Conservation Biology 25:777-786

mat <- matrix(c(1,2), nrow=1, ncol=2)layout(mat=mat, widths=c(56, 29))

Page 8: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

maxC <- apply(reven.data, MARGIN=2,max)mat <- matrix(1:8,nrow=4,ncol=2, byrow=T)par(mar=c(0,2.5,0,0), oma=c(5,2.5,4,1))layout(mat=mat, widths=c(30,16),heights=30+maxC)

Page 9: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Worm et al. (2009) Science 325:578-585

mat=matrix(c(1,2,3,4,5, 6,7,8,9,10, 0,0,0,0,0, 11,11,11,11,11), nrow=5, ncol=4, byrow=F)layout(mat=mat, heights=c(1,1,1,1,1), widths=c(5,5,3,10))par(oma=c(5,5,1,1),mar=c(0,0,0,0))

Page 10: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Branch et al. (2010) Nature 468:431-435

Main plotmat <- matrix(c(1,2,3,3), nrow=2, ncol=2, byrow=F)

par(oma=c(1,2,1,11), mar=c(3,2,0,1))

layout(mat=mat, widths=c(2,1.3), heights=c(2.2,1))

Trickery for bottom-right “legend” par(xpd=NA)positions <- seq(from=2025,to=2060,length.out=5)ypos <- c(-0.34,0.66)#then commands for rect(), #arrows, axis(at=,pos=), #etc.par(xpd=T)

Page 11: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Source: Melissa Clarkson, http://students.washington.edu/mclarkso/

Page 12: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Source: Melissa Clarkson, http://students.washington.edu/mclarkso/

Page 13: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Source: Melissa Clarkson, http://students.washington.edu/mclarkso/

par(plt=c(0.4, 0.8, 0.2, 0.7)) par(plt)Individual figures are added anywhere and of any size, one at a time. Each plot border is defined as a vector of four values (0 to 1) with positions (left, right, bottom, top)

Page 14: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Source: Melissa Clarkson, http://students.washington.edu/mclarkso/

par(fig=c(0.4, 0.8, 0.2, 0.7)) par(fig)Individual figures are added anywhere and of any size, one at a time. Each figure border is defined as a vector of four values (0 to 1) with positions (left, right, bottom, top)

Page 15: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Using par(fig) and par(plt)Coordinates are given in normalized device space (from 0 to 1) and are specified by: c(left, right, bottom, top)a different order from par or oma

2. Plots can partially overlay other plots

3. Replacing fig= with plt= sets the plot border instead of the figure border

Source: Melissa Clarkson, http://students.washington.edu/mclarkso/

Page 16: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

par(fig=c(0.4,0.7,0.1,0.7))plot(…)

par(new=T)par(fig=c(0.1,0.3,0.05,0.65))plot(…)

par(new=T)par(fig=c(0.2,0.8,0.75,0.9))plot(…)

Figures at arbitrary (non-grid) locations using fig

Page 17: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

mat <- matrix(c(0.0, 0.1, 0.9, 1.0, 0.0, 0.3, 0.7, 1.0, 0.1, 0.6, 0.4, 1.0, 0.3, 1.0, 0.0, 0.7), nrow=4,ncol=4,byrow=T)par(mar=c(0,0,0,0), oma=c(1,1,1,1))split.screen(figs=mat)for (i in 1:4) { screen(n=i, new=F) plot(…)}close.screen(all.screens=T)

Figures at arbitrary locations using split.screen

Each row in matrix is the outline of a plot from 0 to 1 specified by: c(left, right, bottom, top)a different order from par or oma

Page 18: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

mat <- matrix(c(0.0, 0.1, 0.9, 1.0, 0.0, 0.3, 0.7, 1.0, 0.1, 0.6, 0.4, 1.0, 0.3, 1.0, 0.0, 0.7), nrow=4,ncol=4,byrow=T)par(mar=c(0,0,0,0), oma=c(1,1,1,1))split.screen(figs=mat)for (i in 1:4) { screen(n=i, new=F) plot(…)}close.screen(all.screens=T)

Figures at arbitrary locations using split.screen

0.0 0.1 0.3 0.6 1.00.0

0.4

0.7

0.9

1.0

Page 19: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Branch et al. (2010) Nature 468:431-435

Page 20: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Branch et al. (2010) Nature 468:431-435

Page 21: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Dean’s Visualization Prize

• The class project comprises four figures: three on your own data, one on Porzio et al. (2011)

• The best portfolio of figures will be awarded the Dean’s Visualization Prize by Lisa Graumlich, dean of the College of the Environment

• Judges: Lisa Graumlich, Trevor Branch, Marilyn Ostergren, Liz Neeley

• The prize is attendance at full-day seminar by Edward Tufte (includes copies of his books, more details here http://www.edwardtufte.com/tufte/courses), or a selection of visualization and R books

Page 22: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Porzio et al. (2011) Journal of Experimental Marine Biology and Ecology 400:278-287

Fig. 2. Kite diagram showing the distribution of the most abundant macroalgal species (N3% coverage) in 27 20×20 cm quadrats taken along a pH gradient from S1 (pH=8.1), S2(pH=7.8) and S3 (pH=6.7). R=Rhodophyta, O=Ochrophyta, and C=Chlorophyta.

Class project: Figure 1

Page 23: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

Separate PowerPoint showing past class projects (not posted)

Page 24: Lecture 5 advanced multipanel plots Trevor A. Branch tbranch@uw.edu Beautiful graphics in R, FISH554 SAFS, University of Washington.

http://xkcd.com/688/

First attempt in R