Visualizing Soil Moisture by Depth and Site: Interactive Plot with Dashed Vertical Lines

Here is the code that will achieve this:

library(ggplot2)
library(RColorBrewer)

mypal <- colorRampPalette(brewer.pal(6, "PuBu"))
mypal2 <- colorRampPalette(brewer.pal(6, "YlOrRd"))

ggplot(df3, 
       aes(value, depth, group = type)) +
  geom_path() +
  facet_wrap(~ site) +
  scale_y_reverse() +
  theme_bw(base_size=18) +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
  labs(title = "Soil moisture by depth and site",
       subtitle = "Observed and expected data",
       x = bquote('Soil moisture (' ~m^3~m^-3*')'),
       y = "Depth") +
  scale_color_manual(values = c(mypal(12), mypal2(12))) +
  geom_vline(aes(xintercept = value, color = interaction(as.factor(month), type)), 
             size = 0.5, alpha = 1/8, linetype = 'dashed')

This code will create a plot with the same facets and path as before, but it will also add two vertical lines for each site, using a dashed line style and alternating between blue and red colors.


Last modified on 2024-07-29