I am trying to show tidal height as geom_area on a secondary y-axis, but have been unsuccessful so far.
Here is my code/graph that I currently have:
#Creating pH Time series plots both sites
ggplot(data = RB_EOS,
aes(
x = Time,
y = pH_corrected_average,
color = Site,
group = Site
)) +
geom_line() +
geom_line(aes(y = 7.55 + Tidal_Depth_ft * 0.075),
linetype = "dotdash") +
scale_y_continuous(
name = "pH",
limits = c(7.55, 7.85),
breaks = seq(7.55, 7.85, 0.05),
sec.axis = sec_axis( ~ (. - 7.55) / 0.075,
name = "Tidal Height (ft)",
breaks = seq(0, 4, 1))
) +
geom_point() +
#geom_point(aes(y = 7.55 + Tidal_Depth_ft*0.075)) +
facet_wrap(~ Week, nrow = 3) +
theme_bw(base_size = 13) +
theme(legend.position = "top") +
ggtitle("pH Tidal Trends") +
labs(subtitle = "Summer 2022") +
xlab("Time (PST)") +
ylab("pH") +
scale_x_discrete(guide = guide_axis(angle = 90))
This was the line plot I created of my pH values (y) over time (x), and then I inputted a secondary y-axis to show the tidal height. I was able to show a line of the tidal height (without the points), which I changed to a dotdash- this was done to show the correspondance of that tidal height to the pH values of its respective site, but I am unable to apply the geom_area function appropriately to the secondary y-axis for tidal height to show the values over a tidal cycle over a smoothed tidal area curve.
I tried this code and nothing happened:
#Creating pH Time series plots both sites
ggplot(data = RB_EOS,
aes(
x = Time,
color = Site,
group = Site
)) +
geom_line(aes(y = pH_corrected_average)) +
geom_area(aes(y = 7.55 + Tidal_Depth_ft * 0.075)) +
scale_y_continuous(
name = "pH",
limits = c(7.55, 7.85),
breaks = seq(7.55, 7.85, 0.05),
sec.axis = sec_axis( ~ (. - 7.55) / 0.075,
name = "Tidal Height (ft)",
breaks = seq(0, 4, 1))
) +
geom_point(aes(y = pH_corrected_average)) +
#geom_point(aes(y = 7.55 + Tidal_Depth_ft*0.075)) +
facet_wrap(~ Week, nrow = 3) +
theme_bw(base_size = 13) +
theme(legend.position = "top") +
ggtitle("pH Tidal Trends") +
labs(subtitle = "Summer 2022") +
xlab("Time (PST)") +
ylab("pH") +
scale_x_discrete(guide = guide_axis(angle = 90))
As you can see, it didn't come out the way I expected, any help appreciated. Thanks!