graphs etc., part 2

14
GRAPHS ETC., PART 2 19 September 2014 Sherubtse Training Point plots with error bars Multiple-panel graphs Adjusting figure margins Adding text & lines to graphs

Upload: milek

Post on 07-Jan-2016

36 views

Category:

Documents


1 download

DESCRIPTION

GRAPHS ETC., PART 2. Point plots with error bars Multiple-panel graphs Adjusting figure margins Adding text & lines to graphs. 19 September 2014 Sherubtse Training. MORNING PRACTICE. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: GRAPHS ETC., PART 2

GRAPHS ETC., PART 2

19 September 2014 Sherubtse Training

Point plots with error barsMultiple-panel graphs

Adjusting figure marginsAdding text & lines to graphs

Page 2: GRAPHS ETC., PART 2

MORNING PRACTICE...

Create a data frame of only UWICE MALES HtWt data. Make a scatterplot showing the relationship between height & weight. Learn and use as many par() arguments as possible in your scatterplot.

Page 3: GRAPHS ETC., PART 2

Import the data called 'sightings'

What kind of summary datawould be useful and interestingto display and graph?

Page 4: GRAPHS ETC., PART 2

Use the functions by() and aggregate() to calculate (separately) mean & sd of number of sightings (averaged across 5 transects), by speciesmean.ag <- aggregate(Count~Species, data=sightings, mean)

To calculate mean & sd simultaneously...

mean.sd.ag <- aggregate(Count~Species, data=sightings, FUN=function(x) c(mn=mean(x), stdev=sd(x)))

mean.by <- by(sightings$Count, sightings$Species, mean)

Page 5: GRAPHS ETC., PART 2

Point Plots

Page 6: GRAPHS ETC., PART 2

Point Plots

o Appropriate for displaying the mean and error of data

o Error bars can represent SD, SE, or 95%CI’s

o Point plots are often underused and under-appreciated—but they are more informative than bar plots for displaying means (not counts)

Page 7: GRAPHS ETC., PART 2

Point Plots or Bar Plots?

To show counts from one transect, use bar plots (or pie charts, for relative frequency) because there would be no error to display

If the data for each species are averaged across 5 different transects, then there WOULD be error associated with the

average # of sightings for each species. In this case, a point plot would show the mean and error better than a bar plot would.

Page 8: GRAPHS ETC., PART 2

Load the package plotrix, import the sightings data, and create this initial point plot showing mean ± SE

To get the filled round points, use the argument pch=16

Page 9: GRAPHS ETC., PART 2

With plotrix, we have to do some things to remove the funny x-values and add buffer on the plot sides...Add these arguments in function plotCI: xaxt="n", xlim=c(0.75,4.25)

Page 10: GRAPHS ETC., PART 2

Learn how to adjust plot margins and add text anywhere you want. Type each line, then run it:

default.par<-par(no.readonly=T) # start by saving default graphic parameterspar(mfrow=c(1,2), oma = c(0,0,3,0))

par(mar=c(6,4,0.5,0.5)) # margins for left-side plotplotCI(mean.by, uiw=SE.by, pch=16, ylab="Mean # of sightings", xaxt="n", xlab="", xlim=c(0.75,4.25)) mtext(names(mean.by), at=1:4, line=0.5, side=1, las=3)

par(mar=c(4,0.5,2,0.5)) # margins for right-side plotplotCI(mean.by, uiw=SE.by, pch=16, xaxt="n", xlab="", ylab="", yaxt="n", xlim=c(0.75,4.25)) mtext("Text indented above plot!", col="blue",side=3, line=0.5)mtext("This is how we place text\nin the outer margins", cex=1.5, col="purple", line=-.5, side = 3, outer=T)

Page 11: GRAPHS ETC., PART 2

To set par back to default: par(default.par)

Page 12: GRAPHS ETC., PART 2

play around with the argument mpg to see what it does

Page 13: GRAPHS ETC., PART 2

What kinds of interesting questions can we ask?What graphs would we make to answer them?

HtWt Data

• Is there a difference in height between UWICE & SFS personnel? Does it differ for males vs. females?

• Is there a difference in weight between UWICE & SFS personnel? Does it differ for males vs. females?

• Is there a relationship between height and weight for UWICE personnel? How about for SFS personnel?

• Is there a relationship between height and weight for males? How about for females?

Page 14: GRAPHS ETC., PART 2