Two weeks ago, we introduced a number of packages within the R “Tidyverse”
Many of your semester project analyses seem to make use of these packages
Challenge today is to apply these packages to an ecological dataset
Goal: Use packages from the tidyverse to create a graph showing the abundance distributions of birds in University Lake near LSU.
Note: In addition to the core tidyverse packages, I used the package glue (but it is not necessary)
To acquire the dataset, please use the following command:
(I previously acquired this dataset using the rebirdpackage, which interacts with the eBird API – see “databases” lecture):
ebird_out <-
crossing(year = c(2023,2024), months = 1:12, date = 1:28) |>
mutate(months = str_pad(months, 2, pad = "0"), date = str_pad(date, 2, pad = "0")) |>
mutate(date_format = glue("{year}-{months}-{date}")) |>
mutate(ebird_out = map(date_format, \(x)
ebirdhistorical(loc = 'L841875',
date = x)))Your goal is to create the plot on the following slide.
Important attributes:
Modify this code to also show Shannon diversity for each month in the title.
Recall that Shannon diversity is calculated as:
\[H' = -\sum_{i=1}^{S} p_i*\text{ln}(p_i)\]
Hint: the following function returns the Shannon diversity for a dataframe (assuming the dataframe has a column named avg_obs). You are welcome to use it in your solution.
Lots of resources to learn more:
dplyr: https://r4ds.hadley.nz/data-transform.html (See also Ch. 5)ggplot2: https://r4ds.hadley.nz/layers.html (See also Ch. 10,11)tidyr: https://r4ds.hadley.nz/data-tidy.htmlforcats: https://r4ds.hadley.nz/factors.htmllubridate: https://r4ds.hadley.nz/datetimes.htmlpurrr: https://r4ds.hadley.nz/program.html (See chapters within this section)stringr: https://r4ds.hadley.nz/strings.html