This document provides a quick summary of trends in southwest Florida tidal creek scores. Functions in the tbeptools R package are used to create the assessment.

library(plotly)
library(tidyverse)
library(tbeptools)

trnds <- tibble(
  yrs = 1975:2024,
) %>% 
  group_nest(yrs) %>% 
  mutate(
    data = purrr::map(yrs, function(x){
      # cat(x, '\t')
      anlz_tdlcrk(tidalcreeks, iwrraw, yr = x)
    }) 
  )

toplo1 <- trnds %>% 
  unnest('data') %>% 
  summarise(
    cnt = n(), 
    .by = c(yrs, score)
  ) %>% 
  mutate(
    score = factor(score, c('Monitor', 'Caution', 'Investigate', 'Prioritize', 'No Data'))
  )

cols <- c(
  Monitor = '#2DC938', 
  Caution = '#E9C318', 
  Investigate = '#EE7600', 
  Prioritize = '#FF4040',
  `No Data` = '#ADD8E6'
)

p1 <- plot_ly(data = toplo1, x = ~yrs, y = ~cnt, color = ~score,
              type = 'bar', legendgroup = ~score, name = ~score,
              colors = cols) %>%
  layout(
    barmode = 'stack',
    showlegend = TRUE,
    xaxis = list(
      title = '',
      showgrid = FALSE,
      zeroline = FALSE
    ),
    yaxis = list(
      title = 'Count',
      showgrid = TRUE,
      zeroline = FALSE
    )
  )

toplo2 <- toplo1 %>% 
  filter(score != 'No Data') %>% 
  mutate(, 
    cnt = cnt / sum(cnt), 
    .by = yrs
  )

p2 <- plot_ly() %>%
  add_bars(data = toplo2, x = ~yrs, y = ~cnt, color = ~score,
           legendgroup = ~score, name = ~score,
           colors = cols, showlegend = FALSE) %>%
  layout(
    barmode = 'stack',
    xaxis = list(
      title = '',
      showgrid = FALSE,
      zeroline = FALSE
    ),
    yaxis = list(
      title = 'Percent with data',
      showgrid = TRUE,
      zeroline = FALSE,
      tickformat = ".0%"
    )
  )

# Combine plots using subplot
subplot(p1, p2, nrows = 2, shareX = TRUE, heights = c(0.5, 0.5), titleY = TRUE) %>%  
  layout(
    barmode = 'stack',
    showlegend = TRUE,
    legend = list(
      orientation = 'h',
      xanchor = 'center',
      x = 0.5,
      y = 1.01,
      yanchor = 'bottom'
    ),
    margin = list(t = 50),
    annotations = list(
      list(
        x = 1,
        y = -0.1,
        text = 'Source: TBEP, Florida Department of Environmental Protection, Impaired Waters Rule, Run 66',
        showarrow = FALSE,
        xref = 'paper',
        yref = 'paper',
        font = list(size = 10)
      )
    )
  )