library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.3.2
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(neonPlantEcology)
library(vegan)
#> Loading required package: permute
#> Loading required package: lattice
#> Warning: package 'lattice' was built under R version 4.3.3
#> This is vegan 2.6-4
library(sf)
#> Warning: package 'sf' was built under R version 4.3.3
#> Linking to GEOS 3.11.2, GDAL 3.8.2, PROJ 9.3.1; sf_use_s2() is TRUE
npe_community_matrix
and {vegan}Load the tidyverse
library along with
neonPlantEcology
. There is a pre-installed dataset which
contains the neonUtilities-generated list object for the Jornada
Experimental Range (“JORN”) and the Santa Rita Experimental Range
(“SRER”) from domain 14. This can be downloaded directly by uncommenting
the following code, or just call data("D14")
.
Use npe_community_matrix
to get the data into the needed
format. By default, it aggregates annually to the (20m x 20m) plot
scale. Use npe_cm_metadata to get all of the information from the
rownames into a more interpretable format. Plot centroids, along with
additional plot-level metadata, can be loaded with
data("plot_centroids")
.
comm[1:4, 1:4]
#> 2PLANT ALLIO AMAC AMFI
#> JORN_001_plot_2017 1.2500000 0.00000000 0.0000 0.00000000
#> JORN_001_plot_2021 0.5833333 0.00000000 0.0000 2.00000000
#> JORN_001_plot_2022 0.0000000 0.08333333 0.0000 0.08333333
#> JORN_001_plot_2016 0.0000000 0.00000000 2.3125 0.00000000
data("plot_centroids")
plot_centroids <- sf::st_set_geometry(plot_centroids, NULL)
metadata <- npe_cm_metadata(comm) |>
dplyr::left_join(plot_centroids)
#> Joining with `by = join_by(plotID)`
#> Warning in dplyr::left_join(npe_cm_metadata(comm), plot_centroids): Detected an unexpected many-to-many relationship between `x` and `y`.
#> ℹ Row 1 of `x` matches multiple rows in `y`.
#> ℹ Row 1001 of `y` matches multiple rows in `x`.
#> ℹ If a many-to-many relationship is expected, set `relationship =
#> "many-to-many"` to silence this warning.
vegan
analysisfirst we’ll do a species accumulation curve for each site.
npe_summary
di <- npe_summary(D14, scale = "site", timescale = "all")
dj<- di |>
dplyr::select(site, eventID, starts_with("nspp")) |>
tidyr::pivot_longer(cols = starts_with("nspp")) |>
dplyr::filter(!name %in% c("nspp_notexotic", "nspp_total")) |>
dplyr::transmute(origin = str_remove_all(name, "nspp_"),
nspp = value,
site=site)
p1<-ggplot(dj, aes(x=nspp, y=site, fill = origin)) +
geom_bar(stat = "identity", color = "black", lwd = .2) +
xlab("Species Richness") +
ylab("Site")
dk<- di |>
dplyr::select(site, eventID, starts_with("rel_cover")) |>
pivot_longer(cols = starts_with("rel_cover")) |>
filter(!name %in% c("rel_cover_notexotic", "rel_cover_total")) |>
transmute(origin = str_remove_all(name, "rel_cover_"),
relative_cover = value,
site=site)
p2<- ggplot(dk, aes(x=relative_cover, y=site, fill = origin)) +
geom_bar(stat = "identity", color = "black", lwd = .2) +
xlab("Relative Cover")
dl <- di|>
dplyr::select(site, eventID, starts_with("shannon")) |>
pivot_longer(cols = starts_with("shannon")) |>
filter(!name %in% c("shannon_notexotic", "shannon_total", "shannon_family")) |>
transmute(origin = str_remove_all(name, "shannon_"),
shannon = value,
site=site)
p3<- ggplot(dl, aes(x = shannon, y = site, fill = origin)) +
geom_bar(stat = 'identity', color = "black", lwd = .2) +
xlab("Shannon-Weiner Diveristy")
npe_longform
data("D14")
lf <- npe_longform(D14, scale = "plot", timescale = "annual")
lf_f <- lf |>
mutate(family = ifelse(!family %in% c("Poaceae", "Fabaceae"), "Other", family)) |>
group_by(site, plotID, eventID, family) |>
summarise(cover = sum(cover, na.rm=T)) |>
ungroup()
#> `summarise()` has grouped output by 'site', 'plotID', 'eventID'. You can
#> override using the `.groups` argument.