【发布时间】:2014-08-18 12:58:11
【问题描述】:
我有一个线图,按rank 因子分组:
ggplot(data=res.sum.df, aes(x=i_id, y=success_rate, colour = rank)) +
geom_line(size=1.5, aes(group=rank))
我有额外的data.frame 对象,它定义了每个等级内所有值的平均值:
> 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
我想用这些平均值添加四条垂直线yintercept,另外根据现有线图例进行着色(分组)。
我尝试添加一些 aes 参数和其他内容,但我的所有组合都失败了(线条没有着色):
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))
【问题讨论】:
-
geom_hline(data = res.sum.df.mean, aes(yintercept = mean_succes_rate, colour=rank))? (作为评论发布,因为问题缺少用于测试的示例数据。) -
谢谢!这确实有效;)