假设我有以下数据,其中汇总了预测因子(X)和调节因子(Z)在低值和高值时的因变量(Dv)的值
dfx <- data.frame(x = rep(c(-0.909, 0.909),2),
z = c(-0.676, -0.676, 0.676, 0.676),
dv = c(448.8, 464.4, 462.8, 472.1))
我想通过自定义both线条类型and标记来绘制dv作为预测器和调节器的函数
library(ggplot2)
dfx$z <- as.factor(dfx$z) # turn the moderator as a factor
ggplot(dfx, aes(x=x, y = dv, colour=z, shape=z))+
geom_line()+
geom_point()+
scale_y_continuous("dv", limits = c(440,480))+
theme_classic()+
scale_colour_manual ("A title", values=c("black", "black"), labels=c("-1SD", "+1SD"))+
scale_shape_manual ("A title", values=c(2,15),labels=c("-1SD","+1SD"))
但是,我也想自定义线型.
当我加上:
ggplot(dfx, aes(x=x, y = dv, colour=z, shape=z, linetype=z)
下面的情节浮出水面.然而,我既不能隐藏第二个标签,也不能通过scale_linetype_manual
个标签对其进行自定义
有什么办法可以解决这个问题吗?我搜索了社区,但没有找到任何方法来克服这个问题.此外,当我 suppress 第二个标签时,图例关键字不会显示线类型和标记. 如有任何提示,将不胜感激.