Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 5 advanced multipanel plots

Similar presentations


Presentation on theme: "Lecture 5 advanced multipanel plots"— Presentation transcript:

1 Lecture 5 advanced multipanel plots
Trevor A. Branch Beautiful graphics in R, FISH554 SAFS, University of Washington

2

3 Visualization courses at UW
FISH 554 Beautiful Graphics in R (Branch, Winter INFO 424 Information Visualization and Aesthetics (Ostergren, Fall INFX 598E Information Visualization for Information Professionals (Ostergren, summer HCDE 411 Information Visualization (Aragon, uses Tableau, HCDE 508 Visual Media (Ostergren, HCDE 511 Information Visualization (Aragon, CSE 512 Information Visualization (Heer, for programmers, uses D3, HTML, R, etc. DESIGN 478 Information Design (Cheng, limited to Design students, HCDE=Human Centered Design & Engineering, INFO=Information School, CSE=Computer Science & Engineering, DESIGN=School of Art, division of Design

4 Five multipanel methods in base R
Methods cannot be combined with each other par(mfrow) or par(mfcol) layout(mat, widths, heights) par(fig) par(plt) split.screen(figs)

5 par(mfrow) Every figure is the same size
Source: Melissa Clarkson,

6

7 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

8 mat <- matrix(c(1,2), nrow=1, ncol=2)
layout(mat=mat, widths=c(56, 29)) Branch et al. (2011) Conservation Biology 25:

9 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)

10 layout(mat=mat, heights=c(1,1,1,1,1), widths=c(5,5,3,10))
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=T) 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)) Worm et al. (2009) Science 325:

11 Trickery for bottom-right “legend”
Main plot mat <- 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) Branch et al. (2010) Nature 468:

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

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

14 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) par(plt=c(0.4, 0.8, 0.2, 0.7)) Source: Melissa Clarkson,

15 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) par(fig=c(0.4, 0.8, 0.2, 0.7)) Source: Melissa Clarkson,

16 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,

17 Figures at arbitrary (non-grid) locations using fig
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)) par(fig=c(0.2,0.8,0.75,0.9))

18 Figures at arbitrary locations using split.screen
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) 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

19 Figures at arbitrary locations using split.screen
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) 1.0 0.9 0.7 0.4 0.0 0.0 0.1 0.3 0.6 1.0

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

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

22 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 or a selection of visualization and R books

23 Class project: Figure 1 Fig. 2. Kite diagram showing the distribution of the most abundant macroalgal species (N3% coverage) in ×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. Porzio et al. (2011) Journal of Experimental Marine Biology and Ecology 400:

24 Separate PowerPoint showing past class projects (not posted)

25 Exercise 1 Create this plot from the data in "CalCurrRevenue
Exercise 1 Create this plot from the data in "CalCurrRevenue.csv" using layout(), par(fig) or par(plt), and split.screen() Fig. 5 Main plot plus subplots, example for ex. 1

26 Exercise 2 (advanced) Reproduce the xkcd cartoon
Exercise 2 (advanced) Reproduce the xkcd cartoon. I suggest using par(fig) to solve this. Concentrate on doing the figures first, not on the text. First attempt in R


Download ppt "Lecture 5 advanced multipanel plots"

Similar presentations


Ads by Google