Skip to content

Commit 2cf8954

Browse files
committed
readable code format
1 parent e546205 commit 2cf8954

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

WWParkFlows.R

+14-12
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ USGS <- USGS %>%
2323
rename(discharge_cfs = X_00060_00003)
2424
WWPark <- USGS[3:4] # Collect only date & discharge
2525

26-
## //
26+
2727
# Get years in quartiles to use as reference
2828
annual <- WWPark %>%
2929
mutate(year = year(Date)) %>%
@@ -39,9 +39,8 @@ avg_annual <- avg_annual %>%
3939
group_by(day_of_year) %>%
4040
summarize(avg_discharge = mean(discharge_cfs))
4141

42-
## \\
4342

44-
## // Collect years and convert date into day of year
43+
## Collect years and convert date into day of year
4544
# Wet
4645
wet <- WWPark %>%
4746
mutate(year = year(Date)) %>%
@@ -109,7 +108,7 @@ dry_months <- dry %>%
109108
mutate(month = month(Date)) %>%
110109
group_by(month) %>%
111110
summarize(avg_discharge = mean(discharge_cfs))
112-
# \\
111+
113112

114113
### FEIS table into R -------------------------------------------------------
115114

@@ -266,7 +265,7 @@ postnisp_avg_annual <- sumpostnisp(C_avg_annual)
266265

267266
threshold <- 355 # Collected from economic survey data
268267

269-
# Historical
268+
## Historical
270269
historicalbday <- function(frame){
271270
frame <- frame[which(frame$discharge_cfs >= threshold),]
272271
frame <- frame %>%
@@ -276,6 +275,7 @@ historicalbday <- function(frame){
276275
summarize(boatabledays = sum(logic))
277276
}
278277

278+
# Find boatable days for each year, and year type
279279
hist_bdays <- historicalbday(WWPark)
280280

281281
wet_hist_bdays <- historicalbday(wet)
@@ -284,7 +284,7 @@ dryTypical_hist_bdays <- historicalbday(dryTypical)
284284
dry_hist_bdays <- historicalbday(dry)
285285

286286

287-
# Post-NISP
287+
## Post-NISP
288288
postnispbday <- function(frame){
289289
frame <- frame[which(frame$avgdischarge_nisp >= threshold),]
290290
frame <- frame %>%
@@ -294,14 +294,16 @@ postnispbday <- function(frame){
294294
summarize(postnisp_boatabledays = sum(logic))
295295
}
296296

297+
# Find boatable days for each year, and year type
297298
postnisp_bdays <- postnispbday(C_avg_annual)
298299

299300
wet_postnisp_bdays <- postnispbday(C_wet)
300301
wetTypical_postnisp_bdays <- postnispbday(C_wetTypical)
301302
dryTypical_postnisp_bdays <- postnispbday(C_dryTypical)
302303
dry_postnisp_bdays <- postnispbday(C_dry)
303304

304-
# Count loss in days in column 'aloss'
305+
306+
# Count loss in days in column 'aloss' using the overall historical bdays data
305307
count <- left_join(hist_bdays, postnisp_bdays, by = "year")
306308
count[is.na(count)] <- 0 # Make N/A values = 0
307309
count <- count %>%
@@ -315,6 +317,7 @@ dfcount <- count %>%
315317

316318
# Plots -------------------------------------------------------------------
317319

320+
## Plots for each year type
318321
plotwet <- ggplot(wet_annual, aes(x = day_of_year, y = avg_discharge)) + geom_line(color = "skyblue2") +
319322
geom_line(data = postnisp_wet, aes(x = day_of_year, y = avg_discharge), color = "slategray") +
320323
scale_y_continuous(breaks = seq(0, 2500, 500), lim = c(0, 2500)) +
@@ -346,15 +349,15 @@ plotavgannual <- ggplot(avg_annual, aes(x = day_of_year, y = avg_discharge)) + g
346349
scale_x_continuous(breaks = c(1,61,122,183,245,306),
347350
labels = c("Jan", "Mar", "May", "Jul", "Sep", "Nov")) # Get every other month
348351

349-
352+
# Figure with all 5 graphs
350353
figure <- ggarrange(plotwet, plotwettyp, plotdry, plotdrytyp,plotavgannual,
351354
labels = c("wet", "wet typical", "dry", "dry typical", "averaged annual"),
352355
ncol = 2, nrow = 3)
353-
print(figure)
354356

357+
print(figure)
355358

356359

357-
# Plot historical boatable days
360+
## Plot historical boatable days
358361
plothist_bdays <- ggplot (data = hist_bdays, aes(x = year, y = boatabledays)) +
359362
geom_bar(stat = "identity", fill = "skyblue2") +
360363
scale_y_continuous(breaks = seq(0, 120, 20), lim = c(0, 120)) +
@@ -363,8 +366,7 @@ plothist_bdays <- ggplot (data = hist_bdays, aes(x = year, y = boatabledays)) +
363366
print(plothist_bdays)
364367

365368

366-
367-
# Plot change in boatable days
369+
## Plot change in boatable days
368370
changeinbdays <- ggplot(data = dfcount, aes(x = year, y = boatabledays, fill = impact)) +
369371
geom_bar(stat = "identity", position = "stack") +
370372
scale_fill_manual(values=c("tomato2", "slategray"),

0 commit comments

Comments
 (0)