Last active
November 13, 2023 02:40
-
-
Save lwaldron/de2875a853af9d1329e2af8513d791af to your computer and use it in GitHub Desktop.
Analyze alpha diversity by year from bugsigdb.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(bugsigdbr) | |
bsdb <- importBugSigDB(version = "devel") | |
# Create a stacked barplot of the proportion of Pielou, Shannon, Chao1, Simpson, Inverse Simpson, and Richness as a function of year | |
library(tidyverse) | |
bsdb_by_year <- bsdb |> | |
filter(Year > 2014) |> | |
dplyr::group_by(Year) |> | |
dplyr::summarize( | |
Pielou = sum(!is.na(Pielou)) / n(), | |
Shannon = sum(!is.na(Shannon)) / n(), | |
Chao1 = sum(!is.na(Chao1)) / n(), | |
Simpson = sum(!is.na(Simpson)) / n(), | |
InverseSimpson = sum(!is.na(`Inverse Simpson`)) / n(), | |
Richness = sum(!is.na(Richness)) / n() | |
) | |
bsdb_by_year_long <- bsdb_by_year |> | |
tidyr::pivot_longer( | |
cols = c(Pielou, Shannon, Chao1, Simpson, InverseSimpson, Richness), | |
names_to = "Metric", | |
values_to = "Value" | |
) | |
ggplot2::ggplot(bsdb_by_year_long, ggplot2::aes(x = Year, y = Value, fill = Metric)) + | |
ggplot2::geom_col(position = "stack") + | |
ggplot2::labs(title = "Reporting of diversity measures by year", | |
x = "Year", | |
y = "Sum of fractions reported") + | |
ggplot2::theme(legend.position = "bottom") | |
# Create a line plot from bsdb_by_year_long of all numeric columns by year | |
png("diversity_by_year.png", width = 4, height = 3.25, units = "in", res = 600) | |
ggplot2::ggplot(bsdb_by_year_long, ggplot2::aes(x = Year, y = Value*100, color = Metric)) + | |
ggplot2::geom_line(linewidth=1.5) + | |
ggplot2::labs(title = "diversity measures over time", | |
x = "Year", | |
y = "% studies reporting") + | |
ggplot2::theme(legend.position = "bottom") | |
dev.off() | |
system("open diversity_by_year.png") | |
lm(Shannon ~ Year, data = bsdb_by_year) |> | |
summary() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment