18.1 Introduction

In the previous lesson we made boxplots to explore the distribution of the data. In this lessons we’ll focus on plotting the mean with error bars. Different kinds of error bars are possible, including the standard deviation, standard error, and confidence intervals. Norms for what to plot vary between fields; generally speaking standard error are most common in biology, but 95% CIs are what are recommended by statisticians. As we’ll explain, standard deviations convey one kind of information, while standard errors and confidence intervals convey a very different kind.

18.1.1 Goals & objectives

Create plots to explore the wildlifeR::frogarms data and visualize both variation within the groups using the standard deviation, and how precisely the mean can be estimated using standard errors (SE) and confidence intervals.

18.1.2 Packages

  • ggplot2
  • cowplot
  • ggpubr
  • dplyr

18.1.3 Outline

  • Preliminaries (if needed): load packages, load data, subset data
  • Represent variation with the standard deviation
  • Represent precision of estimated means using SE and 95% CIs

18.1.4 Vocab

  • standard deviation
  • standard error
  • confidence intervals

18.1.5 Preliminaries

Note: The following code doesn’t need to be run if the previous exercises in this section were already run.

18.1.5.1 Load packages

If not already loaded, we need the wildlifeR package, which lives on Github

library(devtools)                    #[P]
install_github("brouwern/wildlifeR")

library(wildlifeR)

We also need several other packages needed for visualization. We’ll use the ggplot2 package for plotting, and the cowplot package for some nice plotting defaults.

library(ggplot2) #[P]
library(cowplot)
library(ggpubr)
library(dplyr)

18.1.5.2 Load data

Load the frogarms data by Buzatto et al (2015) if its not already loaded.

data(frogarms) #[P]

18.1.5.3 Subset your data

The function make_my_data2L() will extact out a random subset of the data. Change “my.code” to your school email address, minus the “(???)” or whatever your affiliation is. This does not need to be done if you did this as part of the previous lesson

my.frogs <- make_my_data2L(dat = frogarms,    #[P]
                           my.code = "nlb24", # <=  change this!
                           cat.var = "sex",
                           n.sample = 20, 
                           with.rep = FALSE)