-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleaning_minimumTime.R
More file actions
56 lines (44 loc) · 1.61 KB
/
cleaning_minimumTime.R
File metadata and controls
56 lines (44 loc) · 1.61 KB
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
# Clean minimum time data
# Load plyr before dplyr to avoid package conflict issues
pacman::p_load(
plyr,
dplyr,
here,
ggplot2
)
# Load data
data <- read.csv(here("data/Great Bay Environmental Data/clean_imputedPMM_Great Bay_environmental data.csv"))
# Source functions needed for this script
source(here("sample_optimization/scripts/minimumTime_functions.R"))
# Clean data ----
# Clean site names
data$sitename <- clean_vec(data$sitename)
# Clean variable_units
data$variable_units <- clean_vec(data$variable_units)
# Re-name columns
variable <- data %>%
rename("response" = "datavalue") %>%
rename("site" = "sitename")
# Set numerical outputs in decimal places, not in scientific notations.
options(scipen = 10)
# Average each variable across sites
variable.1 <- variable %>%
group_by(variable_units, year) %>%
summarize(response = mean(response))
# Organize each site data into one place by creating a nested data frame
variable.nest <- variable.1 %>%
group_by(variable_units) %>%
tidyr::nest()
# Remove unwanted environmental variables
variable.test <- variable %>%
filter(!variable_units %in% c("nitrogen_ammonia_as_n_dissolved_mg_l",
"nitrogen_dissolved_total_mg_l",
"ph_none",
"phosphorus_as_p_total_mg_l",
"phosphorus_orthophosphate_as_p_dissolved_mg_l",
"turbidity_ntu"))
# Plot results to visualize trends
ggplot(variable.test, aes(x = year, y = response, color = site)) +
geom_point() +
geom_line() +
facet_wrap(~variable_units)