Created
December 17, 2021 14:21
-
-
Save fkeck/05719cedacc931af1c427bb132f2edb1 to your computer and use it in GitHub Desktop.
tidy vegan specaccum plot for ggplot2
This file contains hidden or 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
| #' Convert vegan specaccum results to tidy format | |
| #' | |
| #' @param x result returned by specaccum | |
| #' | |
| #' @return A data.frame in "long format". | |
| #' | |
| tidy_specaccum <- function(x) { | |
| data.frame( | |
| site = x$sites, | |
| richness = x$richness, | |
| sd = x$sd) | |
| } | |
| library(vegan) | |
| library(ggplot2) | |
| library(magrittr) | |
| data(BCI) | |
| # Fit rarefaction curves with vegan | |
| sac <- specaccum(BCI) | |
| # Tidying | |
| tidy_sac <- tidy_specaccum(sac) | |
| # Plot with ggplot | |
| tidy_sac %>% | |
| ggplot() + | |
| geom_line(aes(site, richness)) + | |
| geom_linerange(aes(x = site, ymin = richness - 2*sd, ymax = richness + 2*sd)) + | |
| ylim(0, NA) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment