---
title: "Twigs"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Twigs}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
## Background
Twigs are the smallest above ground woody component of a tree. Twigs are responsible for supporting the delicate tissues needed to grow leaves and protect the buds during the dormant season. Because twig measurements are the basis for the Real Twig method, and publicly available databases of twigs are limited, we present a database of twig measurements for a wide range of tree genera and species.
## Installation
You can install the package directly from [CRAN](https://CRAN.R-project.org):
```{r, eval=FALSE}
install.packages("rTwig")
```
Or the latest development version from [GitHub](https://github.com/):
```{r, eval=FALSE}
devtools::install_github("https://github.com/aidanmorales/rTwig")
```
## Load Packages
The first step is to load the rTwig package.
```{r, message=FALSE}
library(rTwig)
# Useful packages
library(dplyr)
library(ggplot2)
```
## Twig Database
The twig database is built directly into rTwig and can be called as follows:
```{r, eval=FALSE}
# If the rTwig library has been loaded
twigs
```
```{r}
# If rTwig hasn't been loaded, but just the twigs are needed
rTwig::twigs
```
The database is broken into 7 different columns. *scientific_name* is the specific epithet. Genus spp. is the average of all of the species in the genus. *radius_mm* is the twig radius in millimeters. For each species, *n* is the number of unique twig samples taken, *min* is the minimum twig radius, *max* is the max twig radius, *std* is the standard deviation, and *cv* is the coefficient of variation.
Let's see the breakdown of species.
```{r}
unique(twigs$scientific_name)
```
## Visualization
Let's visualize some of the twig data!
```{r fig.height=6, fig.width=7}
# Lets look at a subset of oak species
twigs %>%
filter(grepl("Quercus", scientific_name)) %>%
ggplot(aes(x = scientific_name, y = radius_mm, color = scientific_name)) +
geom_point(aes(size = n)) +
geom_errorbar(aes(ymax = max, ymin = min)) +
coord_flip() +
labs(
title = "Quercus Twig Radii",
x = "",
y = "Twig Radius (mm)",
color = "Species",
size = "Sample Size"
) +
scale_x_discrete(limits = rev) +
theme_classic()
```