knitr::opts_chunk$set( collapse = TRUE, comment = "#>", echo = TRUE, message=F, warning=F)
npstools
& Configure Path to TablesYou only need to run this once, or again to update package.
library(devtools) # install.packages("devtools") devtools::install_github("ecoquants/npstools") # devtools::install() # for developing R package
You'll need access to the databaes tables in comma-seperated value (CSV) format. If you don't have access to the shared drive where they're stored internally, you can use this copy:
You'll then need to unzip the contents and create your own configuration file with this path, similar to:
It is recommended that you setup this file in your home directory "~/nps_config.yaml"
or an RStudio Project so you can reference it with here::here("nps_config.yaml")
.
TODO: Use rstudio/config: config package for R.
# load libraries #library(npstools) devtools::load_all() library(tidyverse) library(here) library(glue) # load your own configuration, which could be based off package nps_config_yaml <- system.file(package="npstools", "nps_config.yaml") cfg <- get_nps_config(nps_config_yaml) # specify park and year of interest park <- "CABR" # "CABR" | "CHIS" | "SAMO" year <- 2015
Table E.6. Species richness (per transect) observed in 20XX monitoring of [PARK] vegetation.
# set optional path to Excel spreadsheet output #n_spp_xlsx <- here(glue("data/spp_richness_pivot_{park}_{year}.xlsx")) # get species richness pivot table n_spp_tbl <- get_n_spp_pivtbl(cfg, park, year) # , xlsx=n_spp_xlsx) # render pivot table as html widget n_spp_tbl$renderPivot()
Table of data for...
Figure E.2. Absolute foliar cover (%) of plant growth forms, as observed during 20XX monitoring at CABR. Colored bars show mean values, while error bars extend ±1 s.d. from the means.
# get percent cover pct_cover_tbl <- get_pct_cover_tbl(cfg, park, year) # render interactive table, without Query_type column pct_cover_tbl %>% select(-Query_type) %>% DT::datatable() %>% DT::formatRound(columns=c("Average", "StdDev"), digits=3)
# render static table, for first 10 rows without Query_type column pct_cover_tbl %>% head(10) %>% select(-Query_type) %>% knitr::kable(digits=3)
TODO:
library(tidyverse) library(leaflet) library(mapview) library(glue) library(sf) to_lonlat <- function(x, y, crs_str){ st_as_sf(data_frame(x=x, y=y), crs=crs_str, coords = c("x", "y")) %>% st_transform(crs=4326) %>% st_coordinates() } locations <- tbl_Locations %>% mutate( # fix one location Y_Coord = ifelse(Location_ID == 1502833764, B_Y_Coord, Y_Coord)) %>% # TODO: fix other locations filter(!is.na(X_Coord), !is.na(Y_Coord), !is.na(UTM_Zone)) %>% mutate( crs_str = glue("+proj={tolower(Coord_System)} +zone={UTM_Zone} +datum={Datum} +units={c(meters='m')[Coord_Units]}"), lon_lat = pmap(list(X_Coord, Y_Coord, crs_str), to_lonlat), lon = map_dbl(lon_lat, ~.[,1]), lat = map_dbl(lon_lat, ~.[,2])) %>% st_as_sf(coords = c("lon", "lat"), crs=4326) leaflet(locations) %>% addProviderTiles(providers$Esri.OceanBasemap) %>% addMarkers( clusterOptions = markerClusterOptions(), popup = ~glue( "<b>Location_ID</b>: {Location_ID}<br> <b>Vegetation_Community</b>: {Vegetation_Community}<br> <b>Loc_Notes</b>: {Loc_Notes}"))
#devtools::load_all() #n_spp_tbl <- get_n_spp_pivtbl(cfg, park, year) # , xlsx=n_spp_xlsx) tbl_nspp <- attr(n_spp_tbl, "data") #View(tbl_nspp) tbl_nspp_sum <- tbl_nspp %>% group_by(Nativity, Life_Form, Vegetation_Community) %>% summarize( nspp = n()) #table(tbl_nspp_sum$Nativity) #fill=FxnGroup, group=FxnGroup, color=FxnGroup, g <- ggplot(tbl_nspp_sum, aes(x=Vegetation_Community, y=nspp, fill=Life_Form, alpha=Nativity)) + #facet_wrap(~Vegetation_Community) + geom_bar(stat="identity", position="dodge") + # , colour="black" scale_alpha_manual(values=c(1, 0.6, 0.3)) + labs(x="Vegetation Community", y="# Species") + theme(axis.text.x = element_text(angle = 45, hjust = 1)) #coord_flip() # TODO: FxnGroup = "All Sites" g
library(plotly) ggplotly(g)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.