--- title: "Getting started with tidydiversity" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Getting started with tidydiversity} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set(dev.args = list(bg = "white"), collapse = TRUE, comment = "#>") ``` tidydiversity brings biodiversity estimation into the tidyverse. Every function takes a long data frame, with one row per site and species, and returns a tibble you can filter, join and plot with the tools you already use. ```{r setup} library(tidydiversity) library(dplyr) ``` ## The example data tidydiversity ships with real field data from Papua New Guinea. The main example, `png_ants`, records ground-foraging ants at nutrient baits along the Mt Wilhelm elevational gradient, from 200 to 3700 m, in the dry and the wet season (Moses et al. 2023, *Global Ecology and Biogeography*). Each row is one ant species at one bait. ```{r} png_ants ``` Ants recruit to baits, so worker counts measure activity rather than independent individuals. `png_ants` therefore has no `abundance` column: tidydiversity counts each row once, and diversity is estimated from the number of baits at which each species was found. Three more Papua New Guinea datasets cover other designs and taxa: * `png_tree_ants`: every ant nest in 1254 trees in plots at 200, 900 and 1800 m (Plowman et al. 2020). * `png_frogs`: 3390 frogs of 55 species at eight elevations on Mt Wilhelm (Dahl et al. 2024). * `wanang_butterflies`: butterflies counted on 36 days over three years in the Wanang forest dynamics plot (Luk et al. 2019). ## Tidy the community `as_community()` sums repeated records, drops zeros and gives standard column names. Use your own column names through the `site`, `species` and `abundance` arguments. ```{r} ants <- as_community(png_ants, .by = season) ants ``` If your data arrive as a site by species matrix, `community_long()` turns it into long format, and `community_wide()` goes the other way. ```{r} wide <- community_wide(ants, .by = season) wide[, 1:6] ``` ## Grouping All verbs accept `.by`, and they respect `group_by()`: ```{r} png_ants |> group_by(season) |> div_hill(q = 0) |> arrange(desc(diversity)) ``` ## What next * `vignette("alpha-rarefaction")` covers Hill numbers, asymptotic estimates and rarefaction. * `vignette("beta-partitioning")` covers turnover, nestedness, distance decay and beta diversity at equal sample coverage (`beta_hill()`).