Skip to content

Commit

Permalink
added dapis option for all seagrass analyzes and viz
Browse files Browse the repository at this point in the history
  • Loading branch information
fawda123 committed Apr 12, 2024
1 parent 3a7eeb0 commit 5d4c66a
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 47 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tbeptools
Title: Data and Indicators for the Tampa Bay Estuary Program
Version: 2.0.1.9021
Date: 2024-03-20
Version: 2.0.1.9022
Date: 2024-04-12
Authors@R: c(
person(given = "Marcus",
family = "Beck",
Expand Down
8 changes: 4 additions & 4 deletions R/anlz_transectavespp.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @param transectocc data frame returned by \code{\link{anlz_transectocc}}
#' @param bay_segment chr string for the bay segment, one to many of "OTB", "HB", "MTB", "LTB", "BCB"
#' @param yrrng numeric indicating year ranges to evaluate
#' @param species chr string of species to summarize, one to many of "Halodule", "Syringodium", "Thalassia", "Ruppia", "Halophila", "Caulerpa"
#' @param species chr string of species to summarize, one to many of "Halodule", "Syringodium", "Thalassia", "Ruppia", "Halophila", "Caulerpa", "Dapis"
#' @param total logical indicating if total frequency occurrence for all species is also returned
#' @param by_seg logical indicating if separate results by bay segments are retained
#'
Expand All @@ -24,15 +24,15 @@
#' transectocc <- anlz_transectocc(transect)
#' anlz_transectavespp(transectocc)
anlz_transectavespp <- function(transectocc, bay_segment = c('OTB', 'HB', 'MTB', 'LTB', 'BCB'), yrrng = c(1998, 2023),
species = c('Halodule', 'Syringodium', 'Thalassia', 'Ruppia', 'Halophila', 'Caulerpa'),
species = c('Halodule', 'Syringodium', 'Thalassia', 'Ruppia', 'Halophila', 'Caulerpa', 'Dapis'),
total = TRUE, by_seg = FALSE){

# sanity checks
stopifnot(length(yrrng) == 2)
stopifnot(yrrng[1] < yrrng[2])

if(!any(species %in% c('Halodule', 'Syringodium', 'Thalassia', 'Ruppia', 'Halophila', 'Caulerpa')))
stop('Incorrect species, must be one of Halodule, Syringodium, Thalassia, Ruppia, Halophila, Caulerpa')
if(!any(species %in% c('Halodule', 'Syringodium', 'Thalassia', 'Ruppia', 'Halophila', 'Caulerpa', 'Dapis')))
stop('Incorrect species, must be one of Halodule, Syringodium, Thalassia, Ruppia, Halophila, Caulerpa, Dapis')

if(!any(bay_segment %in% c('OTB', 'HB', 'MTB', 'LTB', 'BCB')))
stop('Incorrect bay_segment, must be one of OTB, HB, MTB, LTB, BCB')
Expand Down
6 changes: 4 additions & 2 deletions R/anlz_transectocc.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @return A data frame with abundance and frequency occurrence estimates aggregated by species, transect, and date. The nsites column is the total number of placements that were sampled along a transect for a particular date.
#' @export
#'
#' @details Abundance and frequency occurrence are estimated as in Sherwood et al. 2017, equations 1 and 2. In short, frequency occurrence is estimated as the number of instances a species was observed along a transect divided by the number of placements along a transect and average abundance was estimated as the sum of species-specific Braun-Blanquet scores divided by the number of placements along a transect. The estimates are obtained for all seagrass species including Caulerpa, whereas all attached and drift algae species are aggregated.
#' @details Abundance and frequency occurrence are estimated as in Sherwood et al. 2017, equations 1 and 2. In short, frequency occurrence is estimated as the number of instances a species was observed along a transect divided by the number of placements along a transect and average abundance was estimated as the sum of species-specific Braun-Blanquet scores divided by the number of placements along a transect. The estimates are obtained for all seagrass species including Caulerpa (attached macroalgae) and Dapis (cyanobacteria), whereas all attached and drift algae species are aggregated. Drift or attached macroalgae and cyanobacteria (Dapis) estimates may not be accurate prior to 2021.
#'
#' @concept analyze
#'
Expand All @@ -28,7 +28,9 @@ anlz_transectocc <- function(transect){
Savspecies = ifelse(grepl('Caulerpa', Savspecies), 'Caulerpa',
ifelse(grepl('^AA', Savspecies), 'AA',
ifelse(grepl('^DA', Savspecies), 'DA',
Savspecies
ifelse(grepl('Dapis', Savspecies), 'Dapis',
Savspecies
)
)
)
)
Expand Down
17 changes: 10 additions & 7 deletions R/show_transect.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @return A \code{\link[ggplot2]{ggplot}} object
#' @export
#'
#' @details All sites along a transect that were surveyed are shown in the plot, including those where the selected species were not found. The latter is colored in grey hollow points. Species options include Halodule, Syringodium, Thalassia, Halophila, Ruppia, and/or Caulerpa.
#' @details All sites along a transect that were surveyed are shown in the plot, including those where the selected species were not found. The latter is colored in grey hollow points. Species options include Halodule, Syringodium, Thalassia, Halophila, Ruppia, Caulerpa (attached macroalgae), and/or Dapis (cyanobacteria). Drift or attached macroalgae and cyanobacteria (Dapis) estimates may not be accurate prior to 2021.
#'
#' Note that if \code{plotly = TRUE}, the size legend is not shown.
#'
Expand All @@ -34,19 +34,21 @@
#'
#' # multiple species, one plot
#' show_transect(transect, site = 'S3T10',
#' species = c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa'),
#' species = c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia',
#' 'Caulerpa', 'Dapis'),
#' varplo = 'Abundance')
#'
#' # multiple species, multiple plots
#' show_transect(transect, site = 'S3T10',
#' species = c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa'),
#' species = c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia',
#' 'Caulerpa', 'Dapis'),
#' varplo = 'Abundance', facet = TRUE)
show_transect <- function(transect, site, species = c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa'),
show_transect <- function(transect, site, species = c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa', 'Dapis'),
yrrng = c(1998, 2023), varplo = c('Abundance', 'Blade Length', 'Short Shoot Density'), base_size = 12,
facet = FALSE, ncol = NULL, plotly = FALSE, width = NULL, height = NULL, sppcol = NULL){

# species pool
spp <- c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa')
spp <- c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa', 'Dapis')

# sanity checks
if(!site %in% transect$Transect)
Expand All @@ -61,7 +63,7 @@ show_transect <- function(transect, site, species = c('Halodule', 'Syringodium',
# check correct length of optional color vector
if(!is.null(sppcol))
if(length(sppcol) != length(spp))
stop('sppcol required length is six')
stop('sppcol required length is seven')

varplo <- match.arg(varplo)

Expand All @@ -73,6 +75,7 @@ show_transect <- function(transect, site, species = c('Halodule', 'Syringodium',
dplyr::mutate(
Savspecies = dplyr::case_when(
grepl('Caulerpa', Savspecies) ~ 'Caulerpa',
grepl('Dapis', Savspecies) ~ 'Dapis',
T ~ Savspecies
)
) %>%
Expand All @@ -97,7 +100,7 @@ show_transect <- function(transect, site, species = c('Halodule', 'Syringodium',

# sort color palette so its the same regardless of species selected
if(is.null(sppcol))
sppcol <- c('#ED90A4', '#CCA65A', '#7EBA68', '#6FB1E7', '#00C1B2', '#D400FF')
sppcol <- c('#ED90A4', '#CCA65A', '#7EBA68', '#6FB1E7', '#00C1B2', '#D400FF', '#8B2323')
names(sppcol) <- spp
sppcol <- sppcol[levels(dat$name)]

Expand Down
14 changes: 7 additions & 7 deletions R/show_transectavespp.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @param transectocc data frame returned by \code{\link{anlz_transectocc}}
#' @param bay_segment chr string for the bay segment, one to many of "OTB", "HB", "MTB", "LTB", "BCB"
#' @param yrrng numeric indicating year ranges to evaluate
#' @param species chr string of species to summarize, one to many of "Halodule", "Syringodium", "Thalassia", "Ruppia", "Halophila", "Caulerpa"
#' @param species chr string of species to summarize, one to many of "Halodule", "Syringodium", "Thalassia", "Ruppia", "Halophila", "Caulerpa", "Dapis"
#' @param total logical indicating if total frequency occurrence for all species is also returned, only applies if \code{asreact = FALSE}
#' @param alph numeric indicating alpha value for score category colors
#' @param family optional chr string indicating font family for text labels
Expand All @@ -13,7 +13,7 @@
#' @param height numeric for height of the plot in pixels, only applies of \code{plotly = TRUE}
#' @param sppcol character vector of alternative colors to use for each species, must have length of six
#'
#' @details Results are based on averages across species by date and transect in each bay segment
#' @details Results are based on averages across species by date and transect in each bay segment. Drift or attached macroalgae (e.g., Caulerpa) and cyanobacteria (Dapis) estimates may not be accurate prior to 2021.
#'
#' @return If \code{asreact = F}, a \code{\link[ggplot2]{ggplot}} or \code{\link[plotly]{plotly}} (if \code{plotly = T}) object is returned showing trends over time by species for selected bay segments. If \code{asreact = T}, a \code{\link[reactable]{reactable}} table showing results by year, segment, and species is returned.
#' @export
Expand All @@ -34,14 +34,14 @@
#' transectocc <- anlz_transectocc(transect)
#' show_transectavespp(transectocc)
show_transectavespp <- function(transectocc, bay_segment = c('OTB', 'HB', 'MTB', 'LTB', 'BCB'), yrrng = c(1998, 2023),
species = c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa'),
species = c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa', 'Dapis'),
total = TRUE, alph = 1, family = NA, plotly = FALSE, asreact = FALSE, width = NULL,
height = NULL, sppcol = NULL){

# check correct length of optional color vector
if(!is.null(sppcol)){
if(length(sppcol) != 6)
stop('sppcol required length is six')
if(length(sppcol) != 7)
stop('sppcol required length is seven')

sppcol <- c('#FFFFFF', sppcol)

Expand All @@ -58,8 +58,8 @@ show_transectavespp <- function(transectocc, bay_segment = c('OTB', 'HB', 'MTB',

# sort color palette so its the same regardless of species selected
if(is.null(sppcol))
sppcol <- c('#FFFFFF', '#ED90A4', '#CCA65A', '#7EBA68', '#6FB1E7', '#00C1B2', '#D400FF')
names(sppcol) <- c('total', 'Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa')
sppcol <- c('#FFFFFF', '#ED90A4', '#CCA65A', '#7EBA68', '#6FB1E7', '#00C1B2', '#D400FF', '#8B2323')
names(sppcol) <- c('total', 'Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa', 'Dapis')
sppcol <- sppcol[levels(toplo$Savspecies)]

p <- ggplot2::ggplot(toplo, ggplot2::aes(x = yr, y = fo, fill = Savspecies)) +
Expand Down
10 changes: 5 additions & 5 deletions R/show_transectsum.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @return A \code{\link[plotly]{plotly}} object
#' @export
#'
#' @details This plot provides a quick visual assessment of how frequency occurrence or abundance for multiple species has changed over time at a selected transect.
#' @details This plot provides a quick visual assessment of how frequency occurrence or abundance for multiple species has changed over time at a selected transect. Drift or attached macroalgae (e.g., Caulerpa) and cyanobacteria (Dapis) estimates may not be accurate prior to 2021.
#'
#' @importFrom dplyr %>%
#'
Expand All @@ -22,11 +22,11 @@
#' }
#' transectocc <- anlz_transectocc(transect)
#' show_transectsum(transectocc, site = 'S3T10')
show_transectsum <- function(transectocc, site, species = c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa'),
show_transectsum <- function(transectocc, site, species = c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa', 'Dapis'),
yrrng = c(1998, 2023), abund = FALSE, sppcol = NULL){

# species pool
spp <- c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa')
spp <- c('Halodule', 'Syringodium', 'Thalassia', 'Halophila', 'Ruppia', 'Caulerpa', 'Dapis')

# sanity checks
if(!site %in% transectocc$Transect)
Expand All @@ -41,7 +41,7 @@ show_transectsum <- function(transectocc, site, species = c('Halodule', 'Syringo
# check correct length of optional color vector
if(!is.null(sppcol))
if(length(sppcol) != length(spp))
stop('sppcol required length is six')
stop('sppcol required length is seven')

# sort out variable names and labels
val <- 'foest'
Expand All @@ -67,7 +67,7 @@ show_transectsum <- function(transectocc, site, species = c('Halodule', 'Syringo

# sort color palette so its the same regardless of species selected
if(is.null(sppcol))
sppcol <- c('#ED90A4', '#CCA65A', '#7EBA68', '#6FB1E7', '#00C1B2', '#D400FF')
sppcol <- c('#ED90A4', '#CCA65A', '#7EBA68', '#6FB1E7', '#00C1B2', '#D400FF', '#8B2323')
names(sppcol) <- spp
sppcol <- sppcol[levels(toplo$Savspecies)]

Expand Down
4 changes: 2 additions & 2 deletions R/transect.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Seagrass transect data for Tampa Bay current as of 12062023
#' Seagrass transect data for Tampa Bay current as of 04122024
#'
#' Seagrass transect data for Tampa Bay current as of 12062023
#' Seagrass transect data for Tampa Bay current as of 04122024
#'
#' @format A data frame with 152580 rows and 11 variables:
#' \describe{
Expand Down
Binary file modified data/transect.RData
Binary file not shown.
5 changes: 3 additions & 2 deletions man/anlz_transectavespp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/anlz_transectocc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions man/show_transect.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/show_transectavespp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/show_transectsum.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5d4c66a

Please sign in to comment.