I collected temperature and dissolved oxygen (DO) vertical profiles (from water surface to bottom) during my field surveys in a lake. I am trying to do some data exploration/viz to figure out how to use my data. I am trying to plot all my sites in the same plot by date, one plot for temperature (Temp_C) and one for dissolved oxygen (ODO_mgL) per survey date. I have two "Tows", one is S (start) and one E (end), I am only trying to plot the "S" tows for now.
I am having issues when plotting these, sometimes it comes out weird. I think it is because data was collected every second so there might be too many points. Is there a way I can plot this in a neater way? I would be okay with taking the mean every meter and having one temperature and one DO reading every meter instead of every second (i.e. 1 temp./DO reading at 1 m (average), 2m, 3m, 4m, 5m, etc...).
library(tidyverse)
library(ggplot2)
sonde <- read.csv("SondeRaw/sonde_max_depth_no.up_byTow.csv",header=TRUE)
CH_720 <- sonde %>%
filter(Date == '7/20/2021' & Tow == 'S')
#Temperature plot for all CH sites 07/20/2021
#This one looks good
ggplot(CH_720) + aes(x=Temp_C, y=Depth_m, color = Site) +
geom_line() + scale_y_reverse() + xlim(0,25) +
labs(title="Temperature", x="Temperature (C)",
y="Depth (m)",
caption="JUL 20 CH Sites") +
theme(plot.title=element_text(hjust=0.5),
plot.caption = element_text(face = "italic"))
#Dissolved oxygen plot for all CH sites 07/20/2021
#This one looks weird, particularly for site CH711 near the surface
ggplot(CH_720) + aes(x=ODO_mgL, y=Depth_m, color = Site) +
geom_line() + scale_y_reverse() + xlim(0,11) +
labs(title="Dissolved Oxygen", x="DO (mg/L)",
y="Depth (m)",
caption="JUL 20 CH Sites") +
theme(plot.title=element_text(hjust=0.5),
plot.caption = element_text(face = "italic"))
Access data here: https://github.com/cabanelas/sonde_data Please let me know if you have problems accessing my data, I am still learning how to use GitHub properly. Just uploaded this so you can access what I am working with.
Any help is appreciated. I have not been able to find useful resources online about plotting temperature and dissolved oxygen profiles.
For exploring the data, at least to start with, I suggest using geom_point()
together with geom_line()
. Anyway, the problem you are facing is because you are mapping the independent variable to the y
aesthetic, while geom_line()
expects the independent variable to be mapped to x
. In such cases, one needs to pass orientation = "y"
to geom_line()
. This is a fairly new feature of 'ggplot2'. (The temperature readings a less noisy, so they do not look too bad in your plot but it would anyway be better to also plot temperature as shown bellow for DO, disolved oxygen.)
ggplot(CH_720) + aes(x=ODO_mgL, y=Depth_m, color = Site) +
geom_point() + geom_line(orientation = "y") +
scale_y_reverse() + xlim(0,11) +
labs(title="Dissolved Oxygen", x="DO (mg/L)",
y="Depth (m)",
caption="JUL 20 CH Sites") +
theme(plot.title=element_text(hjust=0.5),
plot.caption = element_text(face = "italic"))
Gives:
Smoothing with a spline makes the trends clearer. I kept the plotting of the observations as points, but made them semitransparent (alpha = 0.33
) to highlight the trend but without removing any information. I disabled the plotting of confidence band; you may want to add it. In geom_smooth()
when using method="loess"
you can play with the value passed to span to adjust how flexible the fitted spline is. I chose 0.3 by trial and error. You can make your on choice.
ggplot(CH_720) + aes(x=ODO_mgL, y=Depth_m, color = Site) +
geom_point(alpha = 0.33) +
geom_smooth(orientation = "y", method = "loess", span = 0.3, se = FALSE) +
scale_y_reverse() +
xlim(0,11) +
labs(title="Dissolved Oxygen", x="DO (mg/L)",
y="Depth (m)",
caption="JUL 20 CH Sites") +
theme(plot.title=element_text(hjust=0.5),
plot.caption = element_text(face = "italic"))
As the trend lines overlap, I made a version with separate panels for the sites. (Splines, when gaps are present in the data sometimes make unexpected bends. To some extent this can be prevented by adjusting the span
.)
ggplot(CH_720) + aes(x=ODO_mgL, y=Depth_m, color = Site) +
geom_point(alpha = 0.33) +
geom_smooth(orientation = "y", method = "loess", span = 0.3, se = FALSE) +
scale_y_reverse() +
xlim(0,11) +
labs(title="Dissolved Oxygen", x="DO (mg/L)",
y="Depth (m)",
caption="JUL 20 CH Sites") +
theme(plot.title=element_text(hjust=0.5),
plot.caption = element_text(face = "italic")) +
facet_wrap(~ Site)
Finally I used a logarithmic scale for DO. This, makes the patterns a bit cleaner, but maybe it is totally inapropriate for your data.
ggplot(CH_720) + aes(x=ODO_mgL, y=Depth_m, color = Site) +
geom_point(alpha = 0.33) +
geom_smooth(orientation = "y", method = "loess", span = 0.4, se = FALSE) +
scale_y_reverse() +
scale_x_log10(limits = c(1, 12)) +
# xlim(0,11) +
labs(title="Dissolved Oxygen", x="DO (mg/L)",
y="Depth (m)",
caption="JUL 20 CH Sites") +
theme(plot.title=element_text(hjust=0.5),
plot.caption = element_text(face = "italic")) +
facet_wrap(~ Site)