Fiddlilng with Data

To learn about the functions of R and the tidyverse, we will explore a dataset from the Long Term Ecological Research program Network. This data describes the body size of fiddler crabs (Minuca pugnax) in salt marshes from Florida to Massachusetts during the summer of 2016. You can read more about this data here

Figure 1: Fiddler crabs (Minuca pugnax). Photo credit: Hannah Floyd on iNaturalist (2023).
Note

The tidyverse is a collection of R packages designed to make data science more intuitive. It using grammar-like structure and is built around tidy data. Read more about it here

Climate change has caused this species to expand its range northward in response to ocean warming. As a result, we can use this data to observe Bergmann’s Rule in action. Bergmann’s Rule predicts that organisms at higher latitudes (more north) will have larger body sizes.

Let’s start exploring the data using R and RStudio to see if the sampled fiddler crabs follow this prediction.

Exploring the Data

We will need to start by installing the packages needed for these evaluations. We can do that with the install.packages() function. This may take a while, but don’t worry, once you’ve installed the packages on your computer once, you won’t need to do it again.

install.packages(c("dplyr", "ggplot2", "lterdatasampler"))

Now that our packages are installed, we need to load them into our R session. We can do this using the library() function, as shown below. This only needs to be done once per session.

library(lterdatasampler)
library(ggplot2)
library(dplyr)

Now that we have the packages loaded, we can get at our data. Let’s call it crab_data.

TipSyntax Alert

The <- symbol assigns a value to a named object in R.
Syntax: name <- value (e.g., x <- 42)
If x doesn’t exist yet, a new object is created; it x does exist, its value is replaced.

data(pie_crab) # load the data
crab_data <- pie_crab # rename the data

Our data comes from 13 different marshes along the east coast of the United States of America.

Figure 2: Study area and sampling locations. Locations are indicated with a red point. Abbreviated site names appear beside each location. Water and air temperature data was collected from monitoring programs, nearby weather stations, and ocean buoys.

Here is the raw data, showing 50 rows of the 392 total. We have columns date in the format YYYY-MM-DD, latitude, site (which is an abbreviated sample location), size (which is carapace size in millimeters), air_temp and air_temp_sd (the air temperature and it’s standard deviation in Celsius), water_temp and water_temp_df (the water temperature and it’s standard deviation), and name (full site name).

TipSyntax Alert

The %>% (or |>) symbol is the forward pipe operator. It takes the value or expression on the left-hand side and passes it as the first argument to the function on the right-hand side.
For example: head(crab_data) is the same as crab_data %>% head()

date latitude site size air_temp air_temp_sd water_temp water_temp_sd name
2016-07-24 30.0 GTM 12.43 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 14.18 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 14.52 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 12.94 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 12.45 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 12.99 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 10.32 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 11.19 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 12.68 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 14.55 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 14.92 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 13.48 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 13.76 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 13.10 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 13.56 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 13.51 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 12.12 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 14.33 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 12.52 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 12.03 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 11.84 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 7.55 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 12.59 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 10.05 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 13.00 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 11.29 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 11.58 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-24 30.0 GTM 7.81 21.792 6.391 24.502 6.121 Guana Tolomoto Matanzas NERR
2016-07-26 31.4 SI 9.26 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 12.58 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 10.51 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 8.09 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 10.96 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 9.55 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 7.28 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 12.66 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 6.64 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 10.56 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 10.62 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 11.11 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 13.39 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 7.65 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 10.33 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 6.91 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 9.45 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 7.96 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 8.86 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 13.63 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 9.55 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 10.75 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 9.09 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 9.09 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 9.08 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 9.73 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 8.88 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 11.42 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 10.86 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-26 31.4 SI 9.18 20.830 7.414 22.064 6.495 Sapelo Island NERR
2016-07-28 33.3 NIB 14.53 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 17.29 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 14.69 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 12.57 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 12.89 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 15.14 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 16.99 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 14.01 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 15.32 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 8.52 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 11.98 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 13.71 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 8.84 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 10.77 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 12.71 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 15.31 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 10.55 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 12.87 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 17.04 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 14.47 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 13.63 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 10.34 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 15.82 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 11.45 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 15.88 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 12.70 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 11.95 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 15.67 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 11.40 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-28 33.3 NIB 9.72 18.967 7.990 21.144 7.164 North Inlet Winyah Bay NERR
2016-07-29 34.0 ZI 14.71 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 12.50 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 14.73 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 13.05 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 12.74 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 12.18 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 13.64 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 13.96 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 15.74 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 13.73 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 14.31 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 13.39 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 11.91 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 9.81 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 10.38 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 11.27 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 11.62 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 12.80 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 11.41 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 13.88 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 11.10 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 11.65 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 9.95 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 9.87 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 8.29 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 8.45 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 15.10 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 11.69 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 9.86 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 8.05 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 10.58 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 13.51 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 10.34 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 11.96 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-07-29 34.0 ZI 14.07 18.631 8.397 20.234 7.651 Zeke's Island NERR
2016-08-01 34.7 RC 14.19 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 11.17 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 13.88 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 17.64 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 17.41 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 12.59 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 13.62 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 16.37 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 13.04 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 10.19 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 14.98 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 13.35 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 11.83 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 11.81 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 13.59 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 11.05 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 12.50 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 12.09 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 11.44 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 10.41 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 10.19 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 9.41 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 9.40 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 10.09 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-01 34.7 RC 10.05 18.631 8.397 20.540 6.998 Rachel Carson NERR
2016-08-09 37.2 VCR 21.29 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 19.36 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 18.30 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 17.33 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 20.78 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 21.35 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 19.15 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 11.66 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 18.71 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 19.76 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 18.79 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 14.20 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 19.01 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 12.94 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 13.30 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 19.90 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 16.70 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 15.04 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 14.93 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 14.04 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 16.11 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 16.22 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 12.66 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 13.99 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 13.15 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 14.65 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 13.84 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 15.93 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 15.06 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-09 37.2 VCR 11.92 14.950 8.410 17.560 8.430 Virginia Coastal Reserve LTER
2016-08-07 39.1 DB 18.06 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 18.30 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 14.21 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 17.35 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 16.60 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 13.46 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 15.08 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 15.81 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 20.32 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 17.33 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 16.64 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 14.92 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 18.45 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 20.38 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 17.19 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 13.06 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 13.90 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 16.01 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 14.27 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 13.50 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 15.00 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 14.30 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 15.12 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 14.25 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 15.36 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 14.26 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 13.28 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 11.46 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 14.36 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-07 39.1 DB 15.89 13.932 9.965 15.657 9.121 Delaware Bay NERR
2016-08-08 39.6 JC 20.92 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 18.36 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 12.12 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 12.84 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 12.83 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 17.56 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 18.39 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 15.33 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 17.93 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 18.35 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 15.78 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 16.03 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 12.22 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 9.58 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 14.39 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 12.74 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 13.48 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 15.52 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 17.84 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 17.91 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 13.37 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 16.96 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 12.20 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 12.14 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 17.01 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 14.62 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 12.37 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 19.20 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 15.63 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-08 39.6 JC 14.62 13.143 9.814 15.051 9.016 Jacques Cousteau NERR
2016-08-09 41.3 CT 15.52 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 15.26 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 15.62 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 16.75 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 15.96 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 12.26 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 11.01 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 13.47 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 16.05 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 16.35 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 16.04 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 15.43 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 16.29 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 13.95 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 17.75 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 12.08 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 12.03 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 11.56 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 15.73 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 17.40 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 11.30 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 12.03 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 17.08 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 12.24 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 11.34 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 19.47 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 13.50 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 15.80 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 17.04 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 18.06 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 12.75 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 11.78 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.3 CT 15.92 12.050 8.810 13.976 6.567 Sixpenny Island - Connecticut
2016-08-09 41.6 NB 20.28 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 19.54 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 21.94 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 16.95 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 15.03 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 16.20 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 21.47 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 17.97 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 18.31 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 16.56 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 18.23 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 17.93 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 17.48 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 17.17 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 17.44 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 14.82 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 13.19 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 13.25 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 14.52 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 17.55 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 20.78 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 18.33 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 17.85 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 14.16 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 15.85 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 14.16 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 15.85 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 17.13 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-28 41.6 NB 17.13 12.205 9.483 17.504 7.865 Narragansett Bay NERR
2016-07-25 41.9 CC 17.39 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 19.33 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 18.84 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 14.80 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 18.07 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 19.31 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 17.10 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 17.17 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 18.39 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 18.94 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 15.58 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 18.82 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 16.25 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 16.63 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 15.54 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 19.27 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 14.40 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 19.85 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 16.74 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 13.84 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 16.54 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 16.07 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 15.28 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 16.69 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 16.79 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 10.62 11.280 8.110 14.010 6.900 Cape Cod
2016-07-25 41.9 CC 15.76 11.280 8.110 14.010 6.900 Cape Cod
2016-08-12 42.2 BC 23.43 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 17.00 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 19.17 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 16.35 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 21.49 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 22.02 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 22.21 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 22.44 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 21.92 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 19.80 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 21.03 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 18.41 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 20.19 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 17.97 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 11.56 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 19.58 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 18.10 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 15.22 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 19.25 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 19.99 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 21.81 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 21.39 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 17.33 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 11.39 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 10.15 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 12.92 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 9.42 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 12.74 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 11.58 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 10.10 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 11.77 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 11.51 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 9.01 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 10.04 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 10.91 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 10.24 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-12 42.2 BC 9.86 11.630 9.530 14.010 6.900 Bare Cove Park
2016-08-13 42.7 PIE 17.58 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 21.19 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 20.20 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 18.75 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 17.54 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 22.13 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 19.51 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 18.09 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 17.98 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 19.96 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 18.94 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 20.37 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 17.75 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 16.29 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 9.92 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 16.18 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 18.06 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 19.37 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 17.52 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 17.71 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 20.42 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 20.24 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 18.67 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 17.92 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 21.20 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 16.25 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 20.32 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek
2016-08-13 42.7 PIE 18.05 10.293 9.450 14.330 4.838 Plum Island Estuary - West Creek

This data set comes with lots of columns! Let’s see how we would be able to narrow it down.

Select function

TipSyntax Alert

Functions in R are reusable blocks of code that accept inputs (arguments), perform operations (body) and return an output. 

Here is a function with a single argument, r

circumference <- function(r) {
  # Function body: what the function does to input r
  2*pi*r
  # this function multiples 2 by pi by r to get the circumference
}

circumference(2)
[1] 12.56637

Here is a function with multiple arguments, x and y

subtract_two_nums <- function(x, y){
  # Function body: what the function does to inputs x and y
  x - y
  # this function subtracts y from x
}

subtract_two_nums(3, 1)
[1] 2

One of the main variables that will be used to answer our question is “size”. But how is crab size determined? Scientists collected crabs at each site (note the abbreviated site names in the column “site” that corresponds to a name in the column “name”) and measured the width of their carapace using calipers. The carapace is the main body of the crab. Have a look at the figure below. This photo isn’t of a fiddler crab, but it shows how measurements are taken!

Figure 3: Dungeness crab carapace measurement technique. The same technique applies to fiddler crabs. Photo credit: California Marine Species Portal.

We can use the select() function to create a new data set that only has the desired columns. Test it out below! Pay attention to how the column names inside the select() functions changes as you change what columns to include.

Note

This example only shows 100 rows of data, but there are 392 in the full dataset.

Filter function

Another important function from the dplyr package is filter(). This function only keeps rows that meet certain conditions. Try it out below. Pay attention to how sites and carapace size are excluded based on the conditions specified in the code.

Note

The output is only showing how the filter() function changes the output using only 100 rows of data as input.

For our final analysis, we will want to keep all of our crab observations, so there is no use for the filter() function. However, there are other situations in data analysis where it could be beneficial. For example, we could use the filter() function to see if there are trends in crab carapace size within a single sampling site. See an example of this, combined with the summarise() function below.

Summarise function

To better understand the summarise() function, we will filter the data to a specific site and calculate some summary statistics about that site.

Note

Summary statistics are numerical measures that condense large data sets into a few key values.

Here, we will look at four summary statistics.

  • Mean: the average of all values in a data set.
  • Median: the middle value when data are sorted in ascending order.
  • Standard Deviation (sd): the typical distance of data points from the mean.
  • Interquartile Range (iqr): the width of the middle 50% of the data.

As mentioned above, if we want to see if crabs at more northern sites are larger, we will want to keep all observations from all the different sites. So instead of filtering by site, we will utilise the group_by() and the summarise() functions compare across sampling locations. Since these samples are taken from multiple sites across a latitudinal gradient, the group by function will help us keep track of the different sites. Test out what happens when you group by site versus when you don’t!

We can see that using the group_by() function is important to see the trend across the sampling sites. Without it, the parameters are summarised across ALL the data, and we can’t compare the different sites to each other.

Plotting Our Data

However, summary statistics only give us a numerical was of seeing the trends. An easy way to quickly see trends in data is to use plotting. Creating plots allows for readers to quickly understand the relationships between variables, without having to compute or sort parameters.

Here we will use the ggplot2 package to visualize the raw data and site means.

Geoms: point and jitter

geom_point() draws one dot per row of your data and places points exactly on their appropriate x and y coordinate, such that if points overlap, you can only see the top one.

geom_jitter() on the other hand, considers the overlapping of points. Using this function instead of geom_point() will place points slightly offset of one another so that individual points are more easily visualized.

Smooth lines

geom_smooth() is a function for ggplots that fits a trend line and confidence band to your data.

There are many available methods that geom_smooth() can use to fit a line to your data, but the most commonly used ones are “lm”, “loess”, and “gam”.

The “lm” option will fit a straight line linear regression to your data.

The “loess” option is the default for geom_smooth(), so if you don’t specify a method it will use “loess” when your dataset has less than 1,000 points. This method fits a curve that follows the local structure of the data.

The “gam” option is best for large data sets (>1,000 observations), which fits a smooth spline.

Themes

But what’s the point of making a plot if you can’t make it pretty! In ggplot2 there are nine built-in themes that control the non-data display elements of your figure. These nine themes are:

  • theme_grey()
  • theme_bw()
  • theme_linedraw()
  • theme_light()
  • theme_dark()
  • theme_minimal()
  • theme_classic()
  • theme_void()
  • theme_test()

Putting it all together

Since our examples before did not create a new named object, I am going to start with the select() and summarise() functions to summarise the data, so that I can use these data in my figure.

I have used the same functions as above, but instead of just running the dplyr functions on the data set, I have created a new named object where I ran these functions.

crab_summary <- crab_data %>% 
  select(site, size, latitude) %>% 
  group_by(site) %>% 
  summarise(mean_size = mean(size), 
            latitude = unique(latitude),
            sd_size = sd(size))

After creating this summary data, I can use both the original and summary data sets to create a beautiful plot.

Figure 4: Fiddler crab carapace size (mm) in relation to latitude. Light grey points represent individual observations, while black larger points show mean values for sample sites. Smooth shows positive relationship between carapace size and latitude.

Using the dropdowns, see if you can create the code by changing the options with the dropdowns. There is only one combination of dropdowns that will create a plot identical to mine above.

Pay close attention to which functions and calls change when you select different drop down options.

The code that made this plot:

Tip

An alternative to creating a separate data set is the use the stat_summary() instead of summarise() + geom_point()

For example:

ggplot(data = crab_data, 
       aes(x = latitude, y = size)) + 
  geom_jitter(color = "grey50", alpha = 0.5) + 
  stat_summary(fun = mean, geom = "point",
               color = 'grey30', size = 3) +
  labs(x = "Latitude", y = "Carapace size (mm)") 

Note how geom_point(crab_summary, ...) was replaced with `stat_summary(fun = mean, geom = “point”) but the mean points would still be the same!

Now that you have created a plot, we can see that body size does indeed increase with latitude. This shows that the data follows the predictions posed by Bergmann’s Rule.

Conclusion

You also now know how to conduct a simple analysis using the dplyr and ggplot2 functions. The beauty of tidyverse packages in R is that they follow an English type grammar structure, so instead of thinking purely in code, you can think about what you want to do to your data and translate that into functions.

A full workflow for this kind of analysis is shared here

We can plot our mean sizes alongside the site label on our map to see that as we go further north, crabs generally become larger.

Figure 5: Study area and sampling locations. Location points are coloured by mean carapace size of the sampled crabs. Abbreviated site names and mean carapace size (mm) appear beside each location. Water and air temperature data was collected from monitoring programs, nearby weather stations, and ocean buoys.