I consider the following plot.
d=data.frame(x=c(1,2,4,5,7,8,9), y=c(0,2,3,5,6,7,9))
d2=data.frame(x=c(1,2,3.5,7.2,9), y=c(0,3,7,1.5,4))
ggplot() + geom_step(data=d, mapping=aes(x=x, y=y)) + geom_step(data=d2, mapping=aes(x=x, y=y), color=2)
We have a plot with multiple (here two) step functions that have different number and location of change points on x
. So I cannot directly add them to the same data.frame
without more data manipulation. What would be the best option to add a legend to this plot?