multipanel plotting in r -...

22
Multipanel plotting in R with base graphics Sean Anderson Nov 2011 [email protected]

Upload: vankhanh

Post on 27-Aug-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

Multipanel plotting in Rwith base graphics

Sean Anderson Nov 2011 [email protected]

Page 2: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

Compared to what?- Tufte

Page 3: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

by handggplot2lattice

Page 4: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

par(mfrow)layout()

split.screen()

Page 5: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

par(mfrow)

Page 6: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

John et al. 1988, Science, 239, p162and reprinted in Tufte, Envisioning Information, p78

par(mfrow)

Page 7: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

www.biosciencemag.org July 2011 / Vol. 61 No. 7

Articles

Figure 1. Beanplots of potential correlates of extinction risk for five groups of vertebrate species in Canada. The short vertical lines indicate species for which data are available. The estimated density of the distribution of values is shown for at-risk (white) and not-at-risk (gray) species in the form of curved polygons (beans). The median of each distribution is shown with a long vertical black line. Note the log-distributed horizontal axes. Missing plots were either data deficient (depth midpoint for freshwater fishes, range area for terrestrial and marine mammals, life span and maximum size for birds) or not applicable (all others). Relative age at maturity is the age at maturity divided by life span. Relative size at maturity is the size at maturity divided by maximum size. Abbreviations: g, grams; m, meters; mm, millimeters; m ! km –2, meters per square kilometer; °, degrees.

Anderson et al. 2011, Bioscience, 61, p538

par(mfrow)

Page 8: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●a

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●b

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●c

●●●●●

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●d

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●e

●●

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●f

●●

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●g

●●

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e●

h●

●●

●●

●●

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●i

Subpopulation mean abundanceSu

bpop

ulat

ion

varia

nce

●j

●●

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●k

●●

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●l

●●

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●m

●●

●●

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●n

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e●o

●●

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●p

Subpopulation mean abundanceSu

bpop

ulat

ion

varia

nce

●q

Subpopulation mean abundance

Subp

opul

atio

n va

rianc

e

●r

Subp

opul

atio

n va

rianc

e

●s

●●

●●

Subp

opul

atio

n va

rianc

e

●t

●●●

Subp

opul

atio

n va

rianc

e

●u

●●

Subp

opul

atio

n va

rianc

e

●v●

●●

Subp

opul

atio

n va

rianc

e

●w●

Subp

opul

atio

n va

rianc

e

●x

log(mean)

log(

varia

nce)

Anderson et al. In Prep.

par(mfrow)

Page 9: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

layout()

Page 10: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

Year that recent fishery began

Tim

e to p

eak (

years

)

Australia

Egypt

Fiji

Indonesia

MadagascarMalaysia

MaldivesMexico

New Caledonia

Papua New Guinea

Philippines

Republic of Korea

Seychelles

Solomon Islands

Tanzania

USA − California

USA − Washington State

(a)

1950 1960 1970 1980 1990 2000

010

20

30

40

50

60

Dis

tance fro

m H

ong K

ong (

km

)

Australia

Canada − East

Canada − West

Chile

Egypt

Fiji

Indonesia

Japan

Madagascar

Malaysia

Maldives

Mexico

New Caledonia

Papua New Guinea

Philippines

Republic of Korea

Solomon Islands

Sri Lanka

Tanzania

US − Alaska

USA − California

USA − Maine

USA − Washington State

(b)

1950 1960 1970 1980 1990 2000

05000

10000

15000

20000

(c)

1960

1970

1980

1990

2000

Year

that re

cent fishery

began

1950

Anderson et al. 2011, Fish. Fish, 12, p317

layout()

Page 11: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

Year that recent fishery began

Tim

e to p

eak (

years

)

Australia

Egypt

Fiji

Indonesia

MadagascarMalaysia

MaldivesMexico

New Caledonia

Papua New Guinea

Philippines

Republic of Korea

Seychelles

Solomon Islands

Tanzania

USA − California

USA − Washington State

(a)

1950 1960 1970 1980 1990 2000

010

20

30

40

50

60

Dis

tance fro

m H

ong K

ong (

km

)

Australia

Canada − East

Canada − West

Chile

Egypt

Fiji

Indonesia

Japan

Madagascar

Malaysia

Maldives

Mexico

New Caledonia

Papua New Guinea

Philippines

Republic of Korea

Solomon Islands

Sri Lanka

Tanzania

US − Alaska

USA − California

USA − Maine

USA − Washington State

(b)

1950 1960 1970 1980 1990 2000

05000

10000

15000

20000

(c)

1960

1970

1980

1990

2000

Year

that re

cent fishery

began

1950

Anderson et al. 2011, Fish. Fish, 12, p317

1 2

3

layout()

Page 12: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

050

010

0015

00

Eastern NewfoundlandSPA (1000 t)

Cod

05

1015

Commercial CPUE (kg/trap)

Cra

b

−1.0

−0.5

0.0

1970 1980 1990 2000 2010

Tem

pera

ture��$

C

010

020

030

040

0

Southern Gulf of St. LawrenceSPA (1000 t)

020

4060

Commercial CPUE (kg/trap)

0.0

0.5

1.0

1.5

1970 1980 1990 2000 2010

050

010

0015

00

Northern NewfoundlandSPA (1000 t)

05

1015

Commercial CPUE (kg/trap)

0.0

1.0

2.0

1970 1980 1990 2000 2010

05

1015

2025

Western Cape BretonRS (1000 t)

020

4060

80

Commercial CPUE (kg/trap)

0.5

1.5

2.5

1970 1980 1990 2000 2010

010

020

030

040

0 Northern Gulf of St. LawrenceSPA (1000 t)

05

1020

Commercial CPUE (kg/trap)

1.0

1.5

2.0

2.5

1970 1980 1990 2000 2010

050

000

1500

00

Eastern Scotian ShelfSPA (1000 t)

Cod

020

6010

0

Commercial CPUE (kg/trap)

Cra

b

1.5

2.5

3.5

1970 1980 1990 2000 2010

Tem

pera

ture��$

C

010

2030

40

Northern Cape BretonRS/SPA (1000 t)

020

4060

80

Commercial CPUE (kg/trap)

2.0

2.5

3.0

3.5

1970 1980 1990 2000 2010

0.0

1.0

2.0

3.0

Southern NewfoundlandRS (Biomass index)

05

1015

Commercial CPUE (kg/trap)

23

45

6

1970 1980 1990 2000 2010

010

2030

40

Gulf of MaineSPA (1000 t)

0.00

00.

004

0.00

8

RS (kg/trap)

4.5

5.5

6.5

1970 1980 1990 2000 2010

010

2030

40

Flemish CapSPA (1000 t)

050

100

150

RS (t)

67

89

11

1970 1980 1990 2000 2010

Year

Boudreau et al. 2011, MEPS, 429, p169

layout()

Page 13: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

050

010

0015

00

Eastern NewfoundlandSPA (1000 t)

Cod

05

1015

Commercial CPUE (kg/trap)

Cra

b

−1.0

−0.5

0.0

1970 1980 1990 2000 2010

Tem

pera

ture��$

C

010

020

030

040

0

Southern Gulf of St. LawrenceSPA (1000 t)

020

4060

Commercial CPUE (kg/trap)

0.0

0.5

1.0

1.5

1970 1980 1990 2000 2010

050

010

0015

00

Northern NewfoundlandSPA (1000 t)

05

1015

Commercial CPUE (kg/trap)

0.0

1.0

2.0

1970 1980 1990 2000 2010

05

1015

2025

Western Cape BretonRS (1000 t)

020

4060

80

Commercial CPUE (kg/trap)

0.5

1.5

2.5

1970 1980 1990 2000 2010

010

020

030

040

0 Northern Gulf of St. LawrenceSPA (1000 t)

05

1020

Commercial CPUE (kg/trap)

1.0

1.5

2.0

2.5

1970 1980 1990 2000 2010

050

000

1500

00

Eastern Scotian ShelfSPA (1000 t)

Cod

020

6010

0

Commercial CPUE (kg/trap)

Cra

b

1.5

2.5

3.5

1970 1980 1990 2000 2010

Tem

pera

ture��$

C

010

2030

40

Northern Cape BretonRS/SPA (1000 t)

020

4060

80

Commercial CPUE (kg/trap)

2.0

2.5

3.0

3.5

1970 1980 1990 2000 2010

0.0

1.0

2.0

3.0

Southern NewfoundlandRS (Biomass index)

05

1015

Commercial CPUE (kg/trap)

23

45

6

1970 1980 1990 2000 2010

010

2030

40

Gulf of MaineSPA (1000 t)

0.00

00.

004

0.00

8

RS (kg/trap)

4.5

5.5

6.5

1970 1980 1990 2000 2010

010

2030

40

Flemish CapSPA (1000 t)

050

100

150

RS (t)

67

89

11

1970 1980 1990 2000 2010

Year

Boudreau et al. 2011, MEPS, 429, p169

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

4041

42

43

44

45

46

47

48

49

50

layout()

Page 14: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

split.screen()

Page 15: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

Taylor et al. 1982, J. Anim. Ecol., 51, p879

split.screen()

Page 16: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

0

20

40

60

80

100(a) Original

Perc

enta

ge o

f fish

erie

s

(b) Original static method

Year1960 1970 1960 1970 1980

(d) Revised robust−dynamic method

Collapsed

Overexploited

Fully exploited

Developing

or closed

1990 2000

(c) Revised

0

20

40

60

80

100

Anderson et al. In Review

split.screen()

Page 17: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

METHODS SUMMARYEach taxon in the analysis was assigned a diet-based fractional trophic level, mostlyfrom the online database FishBase24. Primary producers are trophic level one bydefinition, and were not included in our analyses; herbivores and filter feeders aretrophic level two; and omnivores and carnivores are at higher trophic levels. MTLis the catch- or biomass-weighted average of trophic levels of taxa recorded in aparticular year. Ecopath with Ecosim models21 were compiled from well-docu-mented sources and run for 100 years with zero catch to reach unfished states, andthen four main scenarios of fishery development (fishing down3, fishing through6,based on availability19, and increase to overfishing) were applied during years 101to 200. Global catch data were obtained from the United Nations Food andAgriculture Organization (FAO), while catch data for individual Large Marine

Ecosystems came from the Sea Around Us Project of the University of BritishColumbia; trends in catch MTL from these two sources are nearly identical. Long-term scientific trawl surveys from 15 Large Marine Ecosystems provide biomassestimates for regularly recorded taxa, and were obtained from a variety of sources.Biomass estimates for individual taxa were typically not corrected for differentialcatchability among taxa; furthermore, invertebrate biomass estimates were seldomincluded in the provided data. MTL time series from individual surveys werecombined into a single global time series using a linear mixed effects model with‘Large Marine Ecosystem’ modelled as a random effect. Stock assessment biomassvalues were obtained from the RAM Legacy database; total biomass was preferen-tially used in the analysis unless spawning biomass was the only time seriesavailable. Pearson correlations (r) were used to assess whether MTL followed

3.5

4.0

1

2

a Eastern Bering Sea

3.0

3.5

4.0

3

4

5

b Gulf of Alaska

3.0

3.5

4.0 6

c California Current

2.5

3.0

3.5 7

8

d Gulf of Mexico

1950 1965 1980 1995

2.5

3.0

3.5

4.0e Southeast USA

2.5

3.0

3.5

4.0

4.5

910

11

12

13

f Northeast USA

3.0

3.5

4.01415

g Scotian Shelf

3.0

3.5

4.0

4.5

161718h Newfoundland!Labrador

3.5

4.019

20

21

i North Sea

1950 1965 1980 1995

3.5

4.0

22

23j Celtic!Biscay

3.5

4.0

24k Canary Current

3.0

3.5

4.0

4.525

l Benguela Current

3.0

3.5 26mGulf of Thailand

3.0

3.5

4.027

n Northwest Australia

3.5

4.0 o Southeast Australia

1950 1965 1980 1995

3.5

4.0

4.5

2829

p New Zealand

Year

Mea

n tr

ophi

c le

vel

c

a

i

b jh

fe

g97

65

43

12

2321

1716

8

22 2019

1815

141210 1311

k

d

n

m 26

24

p

l

o 2928

27

25

Figure 4 | MTL for each Large Marine Ecosystem. The MTL is shown foreach Large Marine Ecosystem from catches (black lines), assessments (greylines) and surveys (colours). The map shows the location of each Large Marine

Ecosystem, highlighting those with data from all three sources (blue), fromcatches and surveys (red), and from catches and assessments (purple).Numbers on the map reflect the approximate centre of each survey.

RESEARCH LETTER

4 3 4 | N A T U R E | V O L 4 6 8 | 1 8 N O V E M B E R 2 0 1 0

Macmillan Publishers Limited. All rights reserved©2010

Branch et al. 2010, Nature, 468, p431

split.screen()

Page 18: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

r = −0.1

0.5

1.5 a

r = 0

b

r = 0.1

k=

2

c

0.5

1.5 d e

k=

16

f

r = −0.5

0.5

1.0

g

r = 0

h

r = 0.5

µ2µ

1=

1

i

0.5

1.0

1.0 1.5 2.0 2.5

j

1.0 1.5 2.0 2.5

k

µ2µ

1=

16

1.0 1.5 2.0 2.5

l

Taylor's power law z−value

Portf

olio

effe

ct

Anderson et al. In Prep.

split.screen()

Page 19: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

split.screen()

0, 0.46 1, 0.461, 0.44

0.75, 0.44

0.75, 0 1, 00.72, 00.37, 0

0.37, 0.44 0.72, 0.440.35, 0.44

0.34, 0

0, 0.43

0, 0

1, 10, 1

Page 20: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

http://xkcd.com/323/

0, 0.46 1, 0.461, 0.44

0.75, 0.44

0.75, 0 1, 00.72, 00.37, 0

0.37, 0.44 0.72, 0.440.35, 0.44

0.34, 0

0, 0.43

0, 0

1, 10, 1

split.screen()

Page 21: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca

http://xkcd.com/323/

split.screen()

Page 22: Multipanel plotting in R - seananderson.caseananderson.ca/courses/11-multipanel/multipanel-slides.pdf · Multipanel plotting in R with base graphics Sean Anderson Nov 2011 scanders@sfu.ca