
###################################################################################################
### Figure S4 isotropy of turbulent kinetic energy dissipation rate (inertial subrange method)
###################################################################################################

# Creates Figure S4 in
# Klaus, M., Durighetto, N., Khan, A. M., Chatton, E., Öquist, M., Peruzzo, P. and Botter, G. (in revision in "npj Hydrosphere").
# Bubble size spectra reveal distinct scaling patterns and downstream sorting in mountain streams 

###########################################################################################
## created by Marcus Klaus, Swedish University of Agricultural Sciences (SLU), Umeå, Sweden
## contact: marcus.klaus@slu.se
## last update: 2026/04/30
###########################################################################################


windows(width = 16, height = 8)
layout(matrix(1:8, 2, 4, byrow = TRUE))
par(mar=c(4.5,5.5,0.5,0.5),las=1,cex=1,mgp=c(3.6, 1, 0))


y <- log10(DataSpot$epsU_isr/DataSpot$epsW_isr)
x <- log10(DataSpot$d)
# Remove NA pairs
ok <- !is.na(x) & !is.na(y)
x_clean <- x[ok]
y_clean <- y[ok]
# Sort by x
ord <- order(x_clean)
x_sorted <- x_clean[ord]
y_sorted <- y_clean[ord]
# Base scatter plot
plot(x_sorted, y_sorted, pch=1, col=adjustcolor("black",alpha.f=0.2), main="",xaxt="n",yaxt="n", ylab=expression(paste(epsilon[u]/epsilon[w])),xlab="d (cm)")
abline(h=0,lty=3)
# Fit loess model
loess_fit <- loess(y_sorted ~ x_sorted)
# Predictions with standard errors
pred <- predict(loess_fit, se=TRUE)
# Add LOESS line
lines(x_sorted, pred$fit, col="blue", lwd=2)
# Add 95% confidence interval
lines(x_sorted, pred$fit + 1.96*pred$se.fit, col="blue", lty=2)
lines(x_sorted, pred$fit - 1.96*pred$se.fit, col="blue", lty=2)
original_ticks <- c(0.1,1,10,100,1000)
axis(1, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(1, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)

axis(2, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9/10, 2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(2, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)

mtext("A)", side = 3, adj = -0.61, line = -1, font = 2, cex = 1)


y <- log10(DataSpot$epsU_isr/DataSpot$epsW_isr)
x <- log10(DataSpot$Q)
# Remove NA pairs
ok <- !is.na(x) & !is.na(y)
x_clean <- x[ok]
y_clean <- y[ok]
# Sort by x
ord <- order(x_clean)
x_sorted <- x_clean[ord]
y_sorted <- y_clean[ord]
# Base scatter plot
plot(x_sorted, y_sorted, pch=1, col=adjustcolor("black",alpha.f=0.2), main="",xaxt="n",yaxt="n", ylab=expression(paste(epsilon[u]/epsilon[w])),xlab=expression(paste("Q (L ", s^-1,")")))
abline(h=0,lty=3)
# Fit loess model
loess_fit <- loess(y_sorted ~ x_sorted)
# Predictions with standard errors
pred <- predict(loess_fit, se=TRUE)
# Add LOESS line
lines(x_sorted, pred$fit, col="blue", lwd=2)
# Add 95% confidence interval
lines(x_sorted, pred$fit + 1.96*pred$se.fit, col="blue", lty=2)
lines(x_sorted, pred$fit - 1.96*pred$se.fit, col="blue", lty=2)
original_ticks <- c(0.1,1,10,100,1000)
axis(1, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(1, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)

axis(2, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9/10, 2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(2, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)


mtext("B)", side = 3, adj = -0.61, line = -1, font = 2, cex = 1)



y <- log10(DataSpot$epsU_isr/DataSpot$epsW_isr)
x <- log10(DataSpot$h)
# Remove NA pairs
ok <- !is.na(x) & !is.na(y)
x_clean <- x[ok]
y_clean <- y[ok]
# Sort by x
ord <- order(x_clean)
x_sorted <- x_clean[ord]
y_sorted <- y_clean[ord]
# Base scatter plot
plot(x_sorted, y_sorted, pch=1, col=adjustcolor("black",alpha.f=0.2), main="",xaxt="n",yaxt="n", ylab=expression(paste(epsilon[u]/epsilon[w])),xlab=expression(paste("h (cm)")))
abline(h=0,lty=3)
# Fit loess model
loess_fit <- loess(y_sorted ~ x_sorted)
# Predictions with standard errors
pred <- predict(loess_fit, se=TRUE)
# Add LOESS line
lines(x_sorted, pred$fit, col="blue", lwd=2)
# Add 95% confidence interval
lines(x_sorted, pred$fit + 1.96*pred$se.fit, col="blue", lty=2)
lines(x_sorted, pred$fit - 1.96*pred$se.fit, col="blue", lty=2)
original_ticks <- c(0.1,1,10,100,1000)
axis(1, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(1, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)

axis(2, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9/10, 2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(2, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)


mtext("C)", side = 3, adj = -0.61, line = -1, font = 2, cex = 1)

y <- log10(DataSpot$epsU_isr/DataSpot$epsW_isr)
x <- log10(DataSpot$l)
# Remove NA pairs
ok <- !is.na(x) & !is.na(y)
x_clean <- x[ok]
y_clean <- y[ok]
# Sort by x
ord <- order(x_clean)
x_sorted <- x_clean[ord]
y_sorted <- y_clean[ord]
# Base scatter plot
plot(x_sorted, y_sorted, pch=1, col=adjustcolor("black",alpha.f=0.2), main="",xaxt="n",yaxt="n",xlim=c(log10(10),log10(100)), ylab=expression(paste(epsilon[u]/epsilon[w])),xlab=expression(paste("l (cm)")))
abline(h=0,lty=3)
# Fit loess model
loess_fit <- loess(y_sorted ~ x_sorted)
# Predictions with standard errors
pred <- predict(loess_fit, se=TRUE)
# Add LOESS line
lines(x_sorted, pred$fit, col="blue", lwd=2)
# Add 95% confidence interval
lines(x_sorted, pred$fit + 1.96*pred$se.fit, col="blue", lty=2)
lines(x_sorted, pred$fit - 1.96*pred$se.fit, col="blue", lty=2)
original_ticks <- c(0.1,1,10,100,1000)
axis(1, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9/10, 2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(1, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)

axis(2, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9/10, 2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(2, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)


mtext("D)", side = 3, adj = -0.61, line = -1, font = 2, cex = 1)






y <- log10(DataSpot$epsV_isr/DataSpot$epsW_isr)
x <- log10(DataSpot$d)
# Remove NA pairs
ok <- !is.na(x) & !is.na(y)
x_clean <- x[ok]
y_clean <- y[ok]
# Sort by x
ord <- order(x_clean)
x_sorted <- x_clean[ord]
y_sorted <- y_clean[ord]
# Base scatter plot
plot(x_sorted, y_sorted, pch=1, col=adjustcolor("black",alpha.f=0.2), main="",xaxt="n",yaxt="n", ylab=expression(paste(epsilon[v]/epsilon[w])),xlab="d (cm)")
abline(h=0,lty=3)
# Fit loess model
loess_fit <- loess(y_sorted ~ x_sorted)
# Predictions with standard errors
pred <- predict(loess_fit, se=TRUE)
# Add LOESS line
lines(x_sorted, pred$fit, col="blue", lwd=2)
# Add 95% confidence interval
lines(x_sorted, pred$fit + 1.96*pred$se.fit, col="blue", lty=2)
lines(x_sorted, pred$fit - 1.96*pred$se.fit, col="blue", lty=2)
original_ticks <- c(0.1,1,10,100,1000)
axis(1, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(1, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)

axis(2, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9/10, 2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(2, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)

mtext("E)", side = 3, adj = -0.61, line = -1, font = 2, cex = 1)


y <- log10(DataSpot$epsV_isr/DataSpot$epsW_isr)
x <- log10(DataSpot$Q)
# Remove NA pairs
ok <- !is.na(x) & !is.na(y)
x_clean <- x[ok]
y_clean <- y[ok]
# Sort by x
ord <- order(x_clean)
x_sorted <- x_clean[ord]
y_sorted <- y_clean[ord]
# Base scatter plot
plot(x_sorted, y_sorted, pch=1, col=adjustcolor("black",alpha.f=0.2), main="",xaxt="n",yaxt="n", ylab=expression(paste(epsilon[v]/epsilon[w])),xlab=expression(paste("Q (L ", s^-1,")")))
abline(h=0,lty=3)
# Fit loess model
loess_fit <- loess(y_sorted ~ x_sorted)
# Predictions with standard errors
pred <- predict(loess_fit, se=TRUE)
# Add LOESS line
lines(x_sorted, pred$fit, col="blue", lwd=2)
# Add 95% confidence interval
lines(x_sorted, pred$fit + 1.96*pred$se.fit, col="blue", lty=2)
lines(x_sorted, pred$fit - 1.96*pred$se.fit, col="blue", lty=2)
original_ticks <- c(0.1,1,10,100,1000)
axis(1, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(1, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)

axis(2, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9/10, 2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(2, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)


mtext("F)", side = 3, adj = -0.61, line = -1, font = 2, cex = 1)



y <- log10(DataSpot$epsV_isr/DataSpot$epsW_isr)
x <- log10(DataSpot$h)
# Remove NA pairs
ok <- !is.na(x) & !is.na(y)
x_clean <- x[ok]
y_clean <- y[ok]
# Sort by x
ord <- order(x_clean)
x_sorted <- x_clean[ord]
y_sorted <- y_clean[ord]
# Base scatter plot
plot(x_sorted, y_sorted, pch=1, col=adjustcolor("black",alpha.f=0.2), main="",xaxt="n",yaxt="n", ylab=expression(paste(epsilon[v]/epsilon[w])),xlab=expression(paste("h (cm)")))
abline(h=0,lty=3)
# Fit loess model
loess_fit <- loess(y_sorted ~ x_sorted)
# Predictions with standard errors
pred <- predict(loess_fit, se=TRUE)
# Add LOESS line
lines(x_sorted, pred$fit, col="blue", lwd=2)
# Add 95% confidence interval
lines(x_sorted, pred$fit + 1.96*pred$se.fit, col="blue", lty=2)
lines(x_sorted, pred$fit - 1.96*pred$se.fit, col="blue", lty=2)
original_ticks <- c(0.1,1,10,100,1000)
axis(1, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(1, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)

axis(2, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9/10, 2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(2, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)

mtext("G)", side = 3, adj = -0.61, line = -1, font = 2, cex = 1)


y <- log10(DataSpot$epsV_isr/DataSpot$epsW_isr)
x <- log10(DataSpot$l)
# Remove NA pairs
ok <- !is.na(x) & !is.na(y)
x_clean <- x[ok]
y_clean <- y[ok]
# Sort by x
ord <- order(x_clean)
x_sorted <- x_clean[ord]
y_sorted <- y_clean[ord]
# Base scatter plot
plot(x_sorted, y_sorted, pch=1, col=adjustcolor("black",alpha.f=0.2), main="",xaxt="n",yaxt="n",xlim=c(log10(10),log10(100)), ylab=expression(paste(epsilon[v]/epsilon[w])),xlab=expression(paste("l (cm)")))
abline(h=0,lty=3)
# Fit loess model
loess_fit <- loess(y_sorted ~ x_sorted)
# Predictions with standard errors
pred <- predict(loess_fit, se=TRUE)
# Add LOESS line
lines(x_sorted, pred$fit, col="blue", lwd=2)
# Add 95% confidence interval
lines(x_sorted, pred$fit + 1.96*pred$se.fit, col="blue", lty=2)
lines(x_sorted, pred$fit - 1.96*pred$se.fit, col="blue", lty=2)
original_ticks <- c(0.1,1,10,100,1000)
axis(1, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9/10, 2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(1, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)

axis(2, at=log10(original_ticks), labels=original_ticks)
minor_ticks <- c(2:9/10, 2:9, 20,30,40,50,60,70,80,90, 200,300,400,500,600,700,800,900, 2000:9000)  # extend as needed
axis(2, at=log10(minor_ticks), labels=FALSE, tck=-0.03)  # tck sets tick length (negative for outside)

mtext("H)", side = 3, adj = -0.61, line = -1, font = 2, cex = 1)


