-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreek_trends.Rmd
116 lines (106 loc) · 2.55 KB
/
creek_trends.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
title: "Tidal creek trends"
author: "M. W. Beck"
date: "`r Sys.Date()`"
output:
html_document:
code_folding: hide
---
This document provides a quick summary of trends in southwest Florida tidal creek scores. Functions in the [tbeptools](https://tbep-tech.github.io/tbeptools/){target="_blank"} R package are used to create the assessment.
```{r setup, warning = F, message = F, out.width='100%'}
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)
)
)
)
```