Skip to content

Commit

Permalink
change water temp vals to rolling 10 day averages
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsayplatt committed Aug 22, 2022
1 parent 311605c commit 101e284
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
25 changes: 21 additions & 4 deletions data-pipeline/2_process/src/clean_param_data.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
clean_param_data <- function(file_in, sites, start_date, end_date) {
readr::read_csv(file_in, show_col_types = FALSE) %>%
filter(site_no %in% sites) %>%
filter(date >= start_date, date <= end_date) %>%
select(site_no, date, param_grp = parm_abbrev, ends_with("_result"))
data_clean <- readr::read_csv(file_in, show_col_types = FALSE) %>%
dplyr::filter(site_no %in% sites) %>%
dplyr::mutate(param_grp = parm_abbrev) %>%
dplyr::arrange(site_no, date) %>%
# Adjust temperature values to be a rolling 10-day `mean_result` values
# before the date filtering so that we include dates outside of the window
convert_temps_to_rolling_mean() %>%
dplyr::filter(date >= start_date, date <= end_date) %>%
dplyr::select(site_no, date, param_grp, ends_with("_result"), plot_value)

}

convert_temps_to_rolling_mean <- function(data_in) {
data_in %>%
dplyr::group_by(site_no, param_grp) %>%
# Calculate the rolling mean per site/param_grp
dplyr::mutate(mean_rolling = zoo::rollmean(mean_result, k = 10, fill=NA, align = "center")) %>%
# Only replace `mean_result` with the rolling mean for temperature
dplyr::mutate(plot_value = ifelse(param_grp == "temp_water", mean_rolling, mean_result)) %>%
dplyr::select(-mean_rolling) %>%
dplyr::ungroup()
}
4 changes: 2 additions & 2 deletions data-pipeline/3_visualize/src/generate_timeseries_figure.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ generate_line_ts_figure <- function(file_out, data_in, plot_label = 'Mean daily
mutate(alpha_val = ifelse(alpha_val > 1, 2 - alpha_val, alpha_val))

p <- ggplot(data = data_in) +
geom_text(data = data_last, aes(x = date, y = mean_result, label = site_label, color = site_label),
geom_text(data = data_last, aes(x = date, y = plot_value, label = site_label, color = site_label),
fontface ="bold", hjust = 0, nudge_x = 0.5) +
geom_text(x = min(data_in$date), y = 107, label = plot_label, color = '#918b8b', size = 5, hjust = 0.10) +
geom_rect(data = gradient_rect, aes(xmin = xleft, xmax = xright, alpha = alpha_val),
ymin = -Inf, ymax = Inf,
fill = '#dedcdc') +
ggalt::geom_xspline(aes(x = date, y = mean_result, color = site_label), size = 1, spline_shape = -0.5) +
ggalt::geom_xspline(aes(x = date, y = plot_value, color = site_label), size = 1, spline_shape = -0.5) +
scale_color_manual(values = color_vals,
breaks = color_val_labels) +
theme_bw() +
Expand Down

0 comments on commit 101e284

Please sign in to comment.