r - Add horizontal lines, grouped by factor -
i have plot lines, grouped rank
factor:
ggplot(data=res.sum.df, aes(x=i_id, y=success_rate, colour = rank)) + geom_line(size=1.5, aes(group=rank))
i have additional data.frame
object define mean value of values within each rank:
> res.sum.df.mean source: local data frame [4 x 2] rank mean_succes_rate 1 1 0.16666667 2 2 0.13735450 3 3 0.13628500 4 4 0.05797931
i add 4 vertical lines of yintercept
these mean values, additionaly coloured (grouped) according existing line legend.
i tried adding aes
argument , other things, combinations failed (lines not coloured):
ggplot(data=res.sum.df, aes(x=i_id, y=success_rate, colour = rank)) + geom_line(size=1.5, aes(group=rank)) + geom_hline(yintercept = res.sum.df.mean$mean_succes_rate, aes(colour=rank))
you need specify intercepts in aesthetic mapping:
geom_hline(data = res.sum.df.mean, aes(yintercept = mean_succes_rate, colour=rank))
Comments
Post a Comment