Skip to content

Commit 58a71be

Browse files
committed
add loadnorm with chl fig
1 parent 499e76b commit 58a71be

6 files changed

Lines changed: 972 additions & 930 deletions

File tree

R/loadnorm.R

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ library(here)
7979
load(url('https://github.com/tbep-tech/load-estimates/raw/refs/heads/main/data/totanndat.RData'))
8080

8181
hy_ref <- 449
82-
tn_ref <- 468
82+
tn_ref <- 486
8383
ptsz <- 2.5
8484

8585
otbdat <- totanndat |>
@@ -154,4 +154,80 @@ svg(here('figs/loadnorm2withref.svg'), width = 7, height = 3, bg = 'transparent'
154154
print(p2)
155155
dev.off()
156156

157+
# loading v chlorophyll -----------------------------------------------------------------------
157158

159+
library(tidyverse)
160+
library(here)
161+
library(tbeptools)
162+
library(patchwork)
163+
164+
load(url('https://github.com/tbep-tech/load-estimates/raw/refs/heads/main/data/totanndat.RData'))
165+
166+
hy_ref <- 449
167+
tn_ref <- 486
168+
tmdl <- 1.08
169+
ptsz <- 1
170+
chl_ref <- 9.3
171+
172+
otbdat <- totanndat |>
173+
filter(bay_segment == 'Old Tampa Bay') |>
174+
mutate(
175+
tn_load_rate = tn_load / hy_load,
176+
tn_load_norm = hy_ref * tn_load_rate
177+
)
178+
179+
toplo1 <- otbdat |>
180+
select(year, tn_load, tn_load_rate, tn_load_norm)
181+
182+
# ggplot with transparent gray background from 1992 to 1994
183+
p1 <- ggplot() +
184+
geom_rect(data = data.frame(x = 0, y = 0), aes(xmin = 1991.5, xmax = 1994.5, ymin = -Inf, ymax = Inf, fill = 'Reference period'), color = NA, alpha = 0.6) +
185+
geom_line(data = toplo1, aes(x = year, y = tn_load_rate), color = rgb(0.7,0.1,0.2,1), linewidth = 1) +
186+
geom_point(data = toplo1, aes(x = year, y = tn_load_rate), pch = 21, fill = 'white', color = rgb(0.7,0.1,0.2,1), size = ptsz, stroke = 2) +
187+
geom_hline(aes(yintercept = tmdl, linetype = 'TMDL'), color = 'black') +
188+
scale_fill_manual(values = 'gray') +
189+
scale_linetype_manual(values = 'dashed') +
190+
theme_minimal() +
191+
theme(
192+
legend.position = 'top',
193+
panel.grid.minor = element_blank()
194+
) +
195+
coord_cartesian(xlim = c(1985, 2021)) +
196+
labs(
197+
x = NULL,
198+
linetype = NULL,
199+
color = NULL,
200+
y = expression(paste('TN (tons per million'~m^{3}, ')')),
201+
fill = NULL
202+
)
203+
204+
toplo2 <- anlz_avedat(epcdata)$ann |>
205+
filter(bay_segment == 'OTB') |>
206+
filter(var == 'mean_chla') |>
207+
filter(yr >= 1985 & yr <= 2021)
208+
209+
p2 <- ggplot() +
210+
geom_rect(data = data.frame(x = 0, y = 0), aes(xmin = 2016.5, xmax = 2021.5, ymin = -Inf, ymax = Inf, fill = '2017 - 2021 RA period'), color = NA, alpha = 0.6) +
211+
geom_line(data = toplo2, aes(x = yr, y = val), color = rgb(0,0.4,0.7,1), linewidth = 1) +
212+
geom_point(data = toplo2, aes(x = yr, y = val), pch = 21, fill = 'white', color = rgb(0,0.4,0.7,1), size = ptsz, stroke = 2) +
213+
geom_hline(aes(yintercept = chl_ref, linetype = 'Chl-a threshold'), color = 'black') +
214+
scale_fill_manual(values = 'gray') +
215+
scale_linetype_manual(values = 'dashed') +
216+
theme_minimal() +
217+
theme(
218+
legend.position = 'top',
219+
panel.grid.minor = element_blank()
220+
) +
221+
labs(
222+
x = NULL,
223+
linetype = NULL,
224+
color = NULL,
225+
y = expression(paste('Chl-a',' (', mu*g~L^{-1}, ')')),
226+
fill = NULL
227+
)
228+
229+
p <- p1 + p2 + plot_layout(ncol = 1)
230+
231+
png(here('figs/loadnormwithchl.png'), width = 9.5, height = 4.5, units = 'in', res = 300)
232+
print(p)
233+
dev.off()

figs/loadnorm1withref.png

-63 Bytes
Loading

0 commit comments

Comments
 (0)