【发布时间】:2017-08-05 16:57:29
【问题描述】:
我正在使用data.frame(下面有dput)来使用geom_abline 绘制三个斜坡:
moderator_value simple_intercept simple_slope
1 -1 -0.02745523 0.2768973
2 0 0.05990693 0.2147829
3 1 0.14726909 0.1526684
我现在拥有的是这段代码:
ggplot() +
geom_abline(data=ablines,
mapping=aes(slope=simple_slope, intercept=simple_intercept),
linetype=c(1,2,3)) +
scale_x_continuous(limits=c(-1.5,2), name="Prejudice") +
scale_y_continuous(limits=c(-.75, .75), name="Authenticity") +
theme_light() +
theme(text=element_text(size=14))
这会返回图形:
我想添加一个图例,用它们的linetype 标记这三个单独的行。我在其他地方查看过 SO,但其中许多说只是将 show_guide 包含在 geom_abline 函数中(现在已弃用以支持 show.legend)并将其设置为 TRUE。这对我不起作用。我也尝试过使用scale_linetype_manual,但没有成功。
如何添加单独标记每条线的图例?我想包含主持人变量的名称以及“-1 SD”、“平均值”和“+1 SD”作为标签。
dput 的ablines 数据:
structure(list(moderator_value = c(-1, 0, 1), simple_intercept = c(-0.0274552251655293,
0.0599069333124192, 0.147269091790368), simple_slope = c(0.276897278474258,
0.214782863579552, 0.152668448684846)), .Names = c("moderator_value",
"simple_intercept", "simple_slope"), row.names = c(NA, 3L), class = "data.frame")
【问题讨论】: