I am currently working with hydrological data provided by stream gages operated by the USGS. I am trying to plot discharge, water temperature and turbidity for a given time period of interest for a specific stream gage. I have created a graph with discharge and water temperature, but I am not sure of a way to add turbidity on the same plot in ggplot2. I know there are ways to do this in base R, but I am hoping to animate this data using gganimate for use in a presentation. Is there a way to use sec_axis to create another secondary axis?
I have seen the previous threads which explain the process of using sec_axis, but I did not see anywhere where there was a solution given for adding a third y-axis.
I have included the code for my dual y-axes graph below and stream data can be retrieved by using the dataRetrieval package by USGS.
siteNo <- "********"
pCode <- c("00060","63680","00010")
start.date <- "yyyy-mm-dd"
end.date <- "yyyy-mm-dd"
YS <- readNWISuv(siteNumbers = siteNo,
parameterCd = pCode, startDate = start.date, endDate = end.date)
YS <- renameNWISColumns(YS)
YS <- YS %>% select(dateTime,Flow_Inst,Turb_Inst, Wtemp_Inst)
YSHG <- YS %>% ggplot(aes(x = dateTime, y = Flow_Inst)) +
geom_line(aes(color = "Dishcharge"))+
geom_line(aes(y = Wtemp_Inst*3000, color = "Temperature"))+
scale_y_continuous("Discharge (cfs)",
sec.axis = sec_axis(~ ./3000,
name = "Water Temperature (celsius)")) +
ylab("Discharge (CFS)")+
xlab('Date')+
theme_classic()+
theme(plot.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
axis.line.x = element_line(color = 'black'),
axis.title.y.left = element_text(color = "blue"),
axis.line.y.left = element_line(color = "blue"),
axis.title.y.right = element_text(color = "red"),
axis.line.y.right = element_line(color = "red"),
legend.position = "none")+
scale_color_manual(values = c("blue","red"))
YSHG