I have generated a plot showing median expected value over time with a 95% confidence interval ribbon plot. But there are two repeated legends. How do I remove the left hand legend?
Thanks for the help. Larry Hunsicker
ggplot(p1, aes(testyrs, yfit, color = StudyID)) +
geom_line() +
scale_color_discrete(name ="CIT Study") +
geom_ribbon(aes(testyrs, ymin = pi_lb, ymax = pi_ub, fill = StudyID),
alpha = .2) +
theme(legend.position = "bottom") +
labs(x = "Years following first PHPI transplant", y = 'HbA1c',
title = "Projected course of HbA1c following PHPI transplant",
subtitle = "Median and 95% credible interval, CIT-07 and CIT-06")
You can merge both legends by giving the same name to both aesthetics, since you haven't provided a REPRoducible EXample (reprex) here is an example using the iris built-in dataset.
library(ggplot2)
ggplot(iris, aes(Petal.Length, Petal.Width, color = Species, fill = Species)) +
geom_line() +
geom_ribbon(aes(ymin = Petal.Width -1, ymax = Petal.Width + 1),
alpha = .2) +
theme(legend.position = "bottom") +
labs(title = "Example",
color = "Species",
fill = "Species")