我用这data.frame
,这下面我有dput
,三个坡映射使用geom_abline
:GGPLOT2:图例标识多个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
标记这三个单独的行。我在其他地方看过,但其中很多人说show_guide
在geom_abline
函数中(现在已经弃用show.legend
),并将其设置为TRUE
。这不适合我。我也尝试过使用scale_linetype_manual
,但没有运气。
如何包含一个分别标记每条线的图例?我想包含主持人变量的名称以及“-1 SD”,“Mean”和“+1 SD”作为标签。
的ablines
数据dput
:
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")