knitr::opts_chunk$set(echo = TRUE, warning = F, message = F) options(width = 10)
```{css echo = FALSE} .indent { margin-left: 25px; font-size: 14px; }
.indent2 { margin-left: 50px; font-size: 12px; }
.drop{ font-family: "Arial",Arial,sans-serif; font-size: 16px; font-weight: bold; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px; }
.fxn{ color:#1942B5; font-size:14px; font-weight: bold; }
.title{ display:none; } / h4{ color:#1942B5; } /
```r print_head <- function(df){ knitr::kable(df[1:6,]) |> #, table.attr = "style='width:60%;'") |> kableExtra::kable_classic(full_width = T, font_size = 12, bootstrap_options = c("condensed")) } library(tidyverse)
install.packages('devtools')
Note that whenever the forestNETN
package is updated, you can rerun this code to install the latest version.
library(devtools) install_github("KateMMiller/forestNETN")
library(forestNETN)
Note that R is not able to connect to files on Sharepoint or MS Teams (b/c Teams also stores all files on Sharepoint). That means you need to store data package files on your local machine or on a network server (e.g. NETN Z drive). The default option for importing data will add the data package views (i.e., flatfiles) to an environment called VIEWS_NETN to your Environment work space (i.e. Environment tab in top right panel). If you would rather import each individual view into your R session, specify with the new_env argument (e.g., importData(new_env = F)
).
The NETN forest data package is organized as a series of stand alone views (i.e., csvs) of stand, tree, sapling, seedling, herbaceous, and soil data. For metadata on each view and the data package overall, refer to the NETN_FHM_2006_2024_metadata.xml file in the data package. A more readable version of the metadata is also available on NPS DataStore: NETN Forest Data Package. Clicking on an individual view and selecting the "Show Data Table Info" button gives you definitions of the columns in an individual view.
Option 1
To import data using the default settings (i.e. run importData()
with no arguments), you must have the NETN SQL database installed on your local machine with the latest local instance. This is largely for internal NPS use.
Import data using default SQL database connection
importData()
Import data via .csv files into the VIEWS_NETN environment. The path should be where csvs are on your machine or server.Option 2
In most cases, you'll import NETN forest data using the csv files in the zipped data package, which can be downloaded on NPS Data Store: NETN Forest Data Package.
importCSV(path = "C:/NETN/R_Dev/data", zip_name = "NETN_Forest_Data_Package_20240926.zip") # update path to location on your computer
Another approach is to use the NPSutils package to download the data package in R, and then import the csvs.
devtools::install_github("nationalparkservice/NPSutils") NPSutils::get_data_package(2306029) importCSV("./data/2306029")
Once you've loaded the forestNETN
package and have imported the data, you can look at the individual views with the following code:
# See list of views names(VIEWS_NETN) # See first 6 rows of Tree Data head(VIEWS_NETN$TreesByEvent_NETN) # View the Seedling Data View(VIEWS_NETN$MicroplotSeedlings_NETN) # Check structure of the stand info view str(VIEWS_NETN$StandInfoPhotos_NETN)
While this approach works, the easier approach is to use the "join" functions in the R pacakge, which access the same files, but allow you to query data based on the park, years sample, species type, etc. See specific join tabs on how to use the various functions.
forestNETN
have help documentation like any R package. To view the help, you can go to the Packages tab and click on forestNETN. That will show you all the functions in the package. Clicking on individual functions will take you to the help documentation for that function.
You can also see the help of a function by running, for example:
?importCSV
If `forestNETN` isn't loaded yet, you'd run:
?forestNETN::importCSV
Each function's help includes a Description, Usage (i.e. function arguments and their defaults), Argument options/definitions, and several examples showing how the function can be used.
This is where you come in! If you notice typos or can think of better descriptions, examples, error messages, etc., please send them my way!
Finally, if you ever want to peak under the hood at the function, you can view it several ways.
If you want to use the print_head() function that shows output in later tabs, run the code below. This function makes the results print cleaner than if you just run head(dataframe)
, which is also fine.
print_head <- function(df){ knitr::kable(df[1:6,]) |> #, table.attr = "style='width:60%;'") |> kableExtra::kable_classic(full_width = F, font_size = 12, bootstrap_options = c("condensed")) }
This function compiles location and visit-level data about each plot, including years sampled, X/Y coordinates taken at the plot center, and notes about the site. This function is often used to join the results of other functions to, to ensure that all plots are represented in the final dataset.
Compile all visits that have occurred in ACAD
acad <- joinLocEvent(park = "ACAD")
Compile the most recent sample of each plot in ACAD
Note that in 2021, two panels were sampled. To get the most recent survey of each plot, the 3rd panel should be dropped.
acad4yr <- joinLocEvent(park = "ACAD", from = 2021, to = 2024) |> dplyr::filter(!(SampleYear %in% 2021 & PanelCode %in% 3)) head(acad4yr)
Compile the most recent sample of each plot in ACAD, excluding stunted woodlands.
Note that in 2021, two panels were sampled. To get the most recent survey of each plot, the 3rd panel should be dropped.
acad4yr <- joinLocEvent(park = "ACAD", from = 2021, to = 2024) |> dplyr::filter(!(SampleYear %in% 2021 & PanelCode %in% 3)) |> dplyr::filter(IsStuntedWoodland == FALSE) head(acad4yr)
Compiles a list of additional species, which are species detected on the plot during a timed 15-minute search of the plot, and only includes species not detected in other protocol modules (i.e. microplots or quadrats).
View additional species for all plots in WEFA
wefa <- joinAdditionalSpecies(park = "WEFA") print_head(wefa)
Compiles coarse wood debris (CWD) volumn data (m3/ha). Coarse woody debris is sampled along three 15m line-intercept transects per plot.
View CWD volume for all plots in ACAD
acad <- joinCWDData(park = "ACAD") print_head(acad)
View CWD volume for the most recent survey of plots in MABI outputting in ft3/acre
mabi_ac <- joinCWDData(park = "MABI", from = 2022, to = 2024, units = "acres") print_head(mabi_ac)
Compiles sapling data collected within three 2-m radius microplots on the plot. Saplings are >=1cm DBH and <10cm DBH.
View sapling data for all plots in ACAD
acad <- joinMicroSaplings(park = "ACAD") print_head(acad)
View sapling data for native canopy-forming species only for all plots in ACAD
acad_natcan <- joinMicroSaplings(park = "ACAD", speciesType = "native", canopyForm = "canopy") print_head(acad_natcan)
Compiles seedling data collected within three 2-m radius microplots on the plot. Seedlings are >=15cm tall and <1cm DBH, and are tallied by size class.
View seedling data for all plots in SARA
sara <- joinMicroSeedlings(park = "SARA") print_head(sara)
View sapling data for native canopy-forming species only for all plots in SARA
sara_natcan <- joinMicroSaplings(park = "SARA", speciesType = "native", canopyForm = "canopy") print_head(sara_natcan)
This function combines the sapling and seedling data from the previous 2 functions and also calculates a regeneration stocking index.
View regeneration data for all plots in ACAD
acad <- joinRegenData(park = "ACAD") print_head(acad)
View sapling data for native canopy-forming species only for all plots in ACAD
acad_natcan <- joinRegenData(park = "ACAD", speciesType = "native", canopyForm = "canopy") print_head(acad_natcan)
Compiles any notes written about the microplots.
View sapling data for most recent survey of plots in MORR
morr <- joinMicroNotes(park = "MORR", from = 2022, to = 2024) print_head(morr)
Compiles shrub and woody vine percent cover data estimated in three 2-m radius microplots. Shrubs must be >=30cm tall to be recorded. Vine cover is only estimated up to 2m tall.
View shrub data for all plots in ACAD
acad <- joinMicroShrubData(park = "ACAD") print_head(acad)
View shrub data for invasive species only for all plots in SARA from most recent survey of plots
sara_exo <- joinMicroShrubData(park = "SARA", speciesType = "invasive") print_head(sara_exo)
Compiles quadrat characteristic cover data collected in eight 1m2 quadrats.
View quadrat characteristic data for the most recent survey of plots in ROVA
rova <- joinMicroSaplings(park = "ROVA", from = 2022, to = 2024) print_head(rova)
Compiles quadrat species cover data collected in eight 1m2 quadrats from the ground up to 1.5m.
View quadrat species data for the most recent survey of plots in ACAD
acad_q4yr <- joinQuadSpecies(park = "ACAD", from = 2021, to = 2024) |> dplyr::filter(!(SampleYear %in% 2021 & PanelCode %in% 3)) print_head(acad_q4yr)
Compiles notes recorded in quadrats.
View quadrat notes for the most recent survey of plots in ROVA
rova <- joinQuadNotes(park = "ROVA", from = 2022, to = 2024) print_head(rova)
Compiles soil chemistry data derived from the lab. Note that soil chemistry data typically take about 6 months to be received from the lab. The latest year of available lab data is 2023. Starting in the 3rd cycle (2014 and later), only a subset of plots per year are sampled for soil chemistry. Note also that soil horizons are QCed based on %TC, so that horizons with >=20% TC are classified as O and horizons <20% TC are classified as A. If this check results in 2 samples with the same horizon, their chemistry is averaged weighted on the depth of each sample.
View soil chemistry data for plots in ACAD from 2014 and later.
acad_soil <- joinSoilLabData(park = "ACAD", from = 2014, to = 2023) print_head(acad_soil)
View soil chemistry data of O horizon only for plots in ACAD from 2014 and later.
acad_soilO <- joinSoilLabData(park = "ACAD", layer = "O", from = 2014, to = 2023) print_head(acad_soilO)
Compiles soil sample data collected in the field.
View soil sample data for plots in ACAD from 2014 and later.
acad_soil <- joinSoilSampleData(park = "ACAD", from = 2014, to = 2024) print_head(acad_soil)
Compiles data collected at the stand level that may help identify groups or covariates for analyses or explain differences among plots.
View stand data for plots in SAGA from all years.
saga_stnd <- joinStandData(park = "SAGA") head(saga_stnd)
View stand data for plots in ACAD from most recent survey of plots.
acad_stnd4 <- joinStandData(park = "ACAD", from = 2021, to = 2024) |> dplyr::filter(!(SampleYear %in% 2021 & PanelCode %in% 3)) head(acad_stnd4)
Compiles major disturbances recorded on a plot, and that only occurred within the last 4 years of sampling.
View stand disturbances recorded for plots in ACAD from all years.
acad_stnd <- joinStandDisturbance(park = "ACAD") print_head(acad_stnd)
View stand disturbances for plots in ACAD from most recent survey of plots.
acad_stnd4 <- joinStandDisturbance(park = "ACAD", from = 2021, to = 2024) |> dplyr::filter(!(SampleYear %in% 2021 & PanelCode %in% 3)) print_head(acad_stnd4)
Compiles live and dead standing tree data for trees >=10cm tall.
Join all tree data from all surveys of plots in ACAD.
acad_live <- joinTreeData(park = "ACAD")
Join live tree data from the most recent survey of plots in ACAD.
acad_live <- joinTreeData(park = "ACAD", status = 'live', from = 2021, to = 2024) |> dplyr::filter(!(SampleYear %in% 2021 & PanelCode %in% 3)) print_head(acad_live)
Join dead tree data from the most recent survey of plots in ACAD.
acad_dead <- joinTreeData(park = "ACAD", status = 'dead', from = 2021, to = 2024) |> dplyr::filter(!(SampleYear %in% 2021 & PanelCode %in% 3)) print_head(acad_dead)
Compiles tree conditions for live and dead standing trees. Only presence of cavities is recorded for dead trees.
Join tree condition data from the most recent survey of plots in ACAD.
acad_cond <- joinTreeConditions(park = "ACAD", from = 2021, to = 2024) |> dplyr::filter(!(SampleYear %in% 2021 & PanelCode %in% 3)) print_head(acad_cond)
Join tree condition data for live trees only from the most recent survey of plots in ACAD.
acad_lcond <- joinTreeConditions(park = "ACAD", status = 'live', from = 2021, to = 2024) |> dplyr::filter(!(SampleYear %in% 2021 & PanelCode %in% 3)) print_head(acad_lcond)
Compiles foliage conditions for live trees.
Join tree foliage condition data from the most recent survey of plots in ACAD.
acad_fcond <- joinTreeFoliageCond(park = "ACAD", from = 2021, to = 2024) |> dplyr::filter(!(SampleYear %in% 2021 & PanelCode %in% 3)) print_head(acad_fcond)
Compiles all notes recorded for trees.
Join tree notes from all visits to plots in ACAD.
acad_notes <- joinTreeNotes(park = "ACAD") print_head(acad_notes)
Compiles all notes recorded for a given visit, including microplot, quadrat and tree notes.
Join visits notes from all plots in ACAD.
acad_vn <- joinVisitNotes(park = "ACAD") print_head(acad_vn)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.