In R, I am trying to create a custom line chart where all the lines are shown on the chart, but the legend for chart is customized to only show two things.
Right now my code:
x = data.frame(runif(20),runif(20)*2,runif(20)*3)
names(x) = c("Run 1", "Run 2", "Run 3")
x$Avg = apply(x, 1, mean)
x$Step = row.names(x)
df = melt(x, id=c("Step"))
ggplot(df, aes(x=Step, y=value, group=variable, color=variable)) +
geom_line()
Result:
I would like to have the chart show all 4 lines (runs 1,2,3 and avg), but for the legend, I want it to read "Avg" and "Individual Runs", where "Avg" is any color I choose, and each of the "Individual Runs" is in gray or some neutral color. This way when I have lots of runs, I see visually see the data but the legend doesnt go off the screen. How do I accomplish this?
