228k views
4 votes
How to change legend labels in line plot with ggplot2?

User Berry
by
7.8k points

1 Answer

1 vote

Final answer:

To change legend labels in a line plot with ggplot2, use the scale_color_manual or scale_fill_manual functions to manually specify the colors and labels for the legend.

Step-by-step explanation:

To change legend labels in a line plot using ggplot2, you can use the scale_color_manual or scale_fill_manual functions. These functions allow you to manually specify the colors and labels for the legend. For example, to change the legend labels to 'A', 'B', and 'C', you can use the following code:

scale_color_manual(values = c('A' = 'red', 'B' = 'blue', 'C' = 'green'))

This will assign the colors red, blue, and green to the labels 'A', 'B', and 'C' respectively.

User Jeff Turner
by
7.2k points