We can recreate your plot quite well with the following data and plotting code (it's always better to include this in your question)
df <- data.frame(Year = rep(2017:2019, each = 12),
Numbered_Months = rep(1:12, 3),
`Rainfall(mm/month)` = c(0.2, 0.25, 2.5, 4.9, 2.1, 1.2, 0.6,
0.3, 0.4, 0.6, 0.65, 0.75, 0.25, 0.15,
0.35, 0.55, 0.6, 0.8, 0.6, 0.55, 0.5,
3.4, 2.9, 2.1, 0.45, 0.4, 0.25, 0.8,
1.4, 0.15, 0.8, 0.85, 0.65, 1.4, 2.3,
0.3))
library(ggplot2)
original <- ggplot(df, aes(Numbered_Months, Rainfall.mm.month.)) +
geom_line(aes(colour = factor(Year))) +
scale_color_manual(values = c("red", "darkblue", "forestgreen")) +
scale_y_continuous(breaks = 1:5) +
scale_x_continuous(breaks = 1:12) +
theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.x = element_text(angle = 90),
panel.grid.minor = element_blank(),
axis.title.y = element_blank(),
legend.position = "none")
original
We can either use the stat_summary
function or just work out what we want to plot and pass that data to ggplot. In this example I have created a little summary data frame to add the monthly means along with the standard error:
library(dplyr)
group_means <- df %>%
group_by(Numbered_Months) %>%
summarize(mean = mean(Rainfall.mm.month.),
sem_low = mean- sd(Rainfall.mm.month.)/sqrt(3),
sem_high = mean + sd(Rainfall.mm.month.)/sqrt(3))
#> `summarise()` ungrouping output (override with `.groups` argument)
original +
geom_ribbon(data = group_means,
aes(y = mean, ymin = sem_low, ymax = sem_high),
alpha = 0.1) +
geom_line(data = group_means, aes(y = mean), linetype = 2, size = 1)
Created on 2020-08-02 by the reprex package (v0.3.0)