I have plotted ten lines in a single graph and I use color=Var2
to let ggplot2 automatically assign a color to each line. Now I would like to change the legend to something like "A1, A2, A3, A4" instead of "2.5, 5, 7.5, 10". Could anyone teach me how to accomplish this?
Attached is the image:
The data looks like:
abc <- melt(prop_combined)
ggplot(data = abc, aes(x = Var1, y = value, group = Var2, color = Var2))
geom_line()
geom_point()
labs(color='NEW LEGEND TITLE')
CodePudding user response:
Try:
ggplot(data = abc, aes(x = Var1, y = value, group = Var2, color = Var2))
geom_line()
geom_point()
scale_colour_gradient(limits = c(0, 10),
breaks = c(0, 2.5, 5, 7.5, 10),
labels = c("A0", "A1", "A2", "A3", "A4"))