-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRidgelinePlots.qmd
More file actions
80 lines (71 loc) · 2.12 KB
/
RidgelinePlots.qmd
File metadata and controls
80 lines (71 loc) · 2.12 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
title: "USGS Ridgeline Plots"
author: "CLB"
format: html
editor: visual
---
```{r}
#| include: false
library(tidyverse, warn.conflicts = F)
library(dataRetrieval)
library(lubridate)
library(ggridges)
```
# Get Data
```{r}
#Get discharge data from NWIS
rawGageQ <- readNWISdv(siteNumbers = "06879650", #Gage number, exaple gage is Kings Creek, KS
parameterCd = "00060", #Discharge
startDate = "1979-04-11", #Start of first water year for selected gage
endDate = today()) #End of last water year
#Rename columns to make sense
gageQ <- renameNWISColumns(rawGageQ) %>%
select(-agency_cd, -Flow_cd) %>%
rename(FlowCFS = Flow) %>% #Label discharge units (cubic feet per second)
mutate(Year = year(Date),
WaterYear = calcWaterYear(Date),
DOY = yday(Date), #for plotting
FlowCMS = round(FlowCFS * 0.028316847, 2)) %>% #cfs to cms
relocate(site_no, Date, DOY, Year, WaterYear, FlowCFS, FlowCMS) %>% #Make nice order
group_by(Year) %>%
filter((n() == 365 & !leap_year(Year)) | (n() == 366 & leap_year(Year))) %>%
ungroup() %>%
filter(DOY <= 365)
```
# Ridgeline Plot
```{r}
qRidges <- gageQ %>%
ggplot(aes(x = DOY, y = Year, height = FlowCMS, group = Year)) +
geom_ridgeline(color = "white", fill = "black", scale = 1, linewidth = 0.6) +
labs(title = "KINGS CREEK, KANSAS", caption = "STREAMFLOW") +
scale_y_reverse()+
theme_void() +
theme(plot.background = element_rect(fill = "black", color = "black"),
panel.background = element_rect(fill = "black", color = "black"),
plot.title = element_text(
color = "white",
hjust = 0.5,
vjust = -1,
size = 45,
family = "Helvetica"),
plot.caption = element_text(
color = "white",
hjust = 0.5,
vjust = 2.5,
size = 40,
family = "Helvetica"))
qRidges #Look at plot
```
## Save Plot
```{r}
#saving size as A4 paper
ggsave(filename = paste0(gageQ$site_no[1], "_Ridge.png"),
plot = qRidges,
device = "png",
path = "Plots",
width = 297,
height = 210,
units = "mm",
limitsize = F,
dpi = 700)
```