I have created a graph with a curve for each individual and a mean curve that is created the same way. I would like to have a confidence interval on my mean curve. How can I do this? Should the mean curve be created in a different way? This is my code until now:
DNAMorfR %>%
drop_na(`Normal morphology (%)`) %>%
ggplot(aes(x = Time, y = `Normal morphology (%)`, linetype = Patient, color = Patient, group
= Patient, na.rm = TRUE)) +
geom_line(size = 1) +
theme_minimal() + ggtitle("(A1) Normal morphology") +
geom_point(size = 1.5) +
scale_y_continuous(limits = c(0, 25), breaks=seq(0, 25, by = 5)) +
geom_hline(yintercept = 4, color = "grey", size = 1) +
scale_color_manual(values = c("black", "#FF3333", "#FF9933", "#CC9900"))
And this is my data:
data.frame(
stringsAsFactors = FALSE,
check.names = FALSE,
Patient = c("1","1","1","2","2","2","3","3","3","mean","mean","mean"),
`Normal morphology (%)` = c(7, 2, 3, 1, 3, 3, 6, 7, 8, 7, 9, 8),
Time = as.factor(c("Week 1","Week 2","Week 3","Week 1","Week 2","Week 3","Week 1","Week 2",
"Week 3","Week 1","Week 2","Week 3")))