ggplot2() with multiple geom_line calls, how to create a legend with matching colors?

If you want a legend then you have to map the aesthetic attribute "color" to a variable (or in this case a value), so you have to put it inside the aes() function, try this way

geom_line(aes(y=likelihood_mtrx[,4], colour="X")) + # fourth layer

If you need more specific help please provide a proper REPRoducible EXample (reprex)

1 Like