knitr::opts_chunk$set(
  collapse = TRUE,
  fig.show = "hold",
  comment = "#>",
  fig.path = "man/figures/README-"
)

Analyze forest diversity and dynamics

lifecycle Travis build status Coverage status CRAN status

# Creates a functional link when used with DT table.
fgeo_link <- function(package, topic = NULL) {
  end <- glue::glue(">{package}")
  if (!is.null(topic)) {end <- glue::glue("/reference/>{topic}")}
  glue::glue("<a href=https://forestgeo.github.io/{package}{end}</a>")
}

link_core <- function(pattern) {
  core <- fgeo_to_attach()()
  fgeo_link(core[grepl(pattern, core)])
}

analyze <- "analyze"
visualize <- "map"
manipulate <- "tool"
datasets <- "x"

fgeo helps you to install, load, and access the documentation of multiple packages to analyze forest diversity and dynamics (r purrr::map_chr(fgeo::fgeo_packages(include_self = FALSE), fgeo_link)). This package-collection allows you to manipulate and plot ForestGEO data, and to do common analyses including abundance, demography, and species-habitats associations.

Installation

Make sure your R environment is as follows:

Install the latest stable version of fgeo from CRAN with:

install.packages("fgeo")

Or install the development version of fgeo from GitHub with:

# install.packages("devtools")
devtools::install_github("forestgeo/fgeo.x")

Example

library(fgeo)

Explore fgeo

On an interactive session, fgeo_help() and fgeo_browse_reference() help you to search documentation.

if (interactive()) {
  # To search on the viewer; accepts keywords
  fgeo_help()
  # To search on a web browser
  fgeo_browse_reference() 
}

Access and manipulate data

example_path() allows you to access datasets stored in your R libraries.

example_path()

(vft_file <- example_path("view/vft_4quad.csv"))

read_<table>()

read_vft() and read_taxa() import a ViewFullTable and ViewTaxonomy from .tsv or .csv files.

read_vft(vft_file)

pick_<what>() and drop_<what>()

fgeo is pipe-friendly. You may not use pipes but often they make code easier to read.

Use %>% to emphasize a sequence of actions, rather than the object that the actions are being performed on.

-- https://style.tidyverse.org/pipes.html

pick_dbh_under(), drop_status() and friends pick and drop rows from a ForestGEO ViewFullTable or census table.

(census <- fgeo.x::tree5)

census %>% 
  pick_dbh_under(100)

pick_main_stem() and pick_main_stemid() pick the main stem or main stemid(s) of each tree in each census.

stem <- download_data("luquillo_stem6_random")

dim(stem)
dim(pick_main_stem(stem))

add_<column(s)>()

add_status_tree()adds the column status_tree based on the status of all stems of each tree.

stem %>% 
  select(CensusID, treeID, stemID, status) %>% 
  add_status_tree()

add_index() and friends add columns to a ForestGEO-like dataframe.

stem %>% 
  select(gx, gy) %>% 
  add_index()

Plot data

For simplicity, we will focus on only a few species.

stem_2sp <- stem %>% 
  filter(sp %in% c("PREMON", "CASARB"))

autoplot() and friends produce different output depending on the class of input. You can create different input classes, for example, with sp() and sp_elev():

class(sp(stem_2sp))

autoplot(sp(stem_2sp))
elevation <- fgeo.x::elevation
class(sp_elev(stem_2sp, elevation))

autoplot(sp_elev(stem_2sp, elevation))

Analyze

Abundance

abundance() and basal_area() calculate abundance and basal area, optionally by groups.

abundance(
  pick_main_stem(census)
)

by_species <- group_by(census, sp)

basal_area(by_species)

Demography

recruitment_ctfs(), mortality_ctfs(), and growth_ctfs() calculate recruitment, mortality, and growth. They all output a list. as_tibble() converts the output from a list to a more convenient dataframe.

tree5 <- fgeo.x::tree5

as_tibble(
  mortality_ctfs(tree5, tree6)
)

Species-habitats association

tt_test() runs a torus translation test to determine habitat associations of tree species. as_tibble() converts the output from a list to a more convenient dataframe. summary() helps you to interpret the result.

# This analysis makes sense only for tree tables
tree <- download_data("luquillo_tree5_random")

habitat <- fgeo.x::habitat
result <- tt_test(tree, habitat)

as_tibble(result)

summary(result)

Downloads of fgeo packages

library(ggplot2)

fgeo::fgeo_packages() %>% 
  cranlogs::cran_downloads(from = "2019-05-09", to = lubridate::today()) %>% 
  ggplot(aes(date, count)) +
    geom_col() +
    labs(caption = "Data from <https://github.com/r-hub/cranlogs>")

Related projects

Additional packages maintained by ForestGEO but not included in fgeo:

Other packages not maintained by ForestGEO:

R code from recent publications by ForestGEO partners

Data have been made available as required by the journal to enable reproduction of the results presented in the paper. Please do not share these data without permission of the ForestGEO plot Principal Investigators (PIs). If you wish to publish papers based on these data, you are also required to get permission from the PIs of the corresponding ForestGEO plots.

Information

Acknowledgments

Thanks to all partners of ForestGEO for sharing their ideas and code. For feedback on fgeo, special thanks to Gabriel Arellano, Stuart Davies, Lauren Krizel, Sean McMahon, and Haley Overstreet. For all other help, I thank contributors in the documentation of the features they helped with.



forestgeo/fgeo documentation built on Dec. 24, 2019, 8:07 p.m.