交互图的平均线

问题描述

有人知道如何在交互作用图上添加均值线吗?我的代码是这样的:

#interaction plot
with(datascen_2minBL,interaction.plot(scenario,role,cw2_sum_ampl_per_min,xlab = "baselines",ylab = "2min sumAmplPerMin"))

每个参与者在不同时间点都有多次回应。每个参与者具有不同的角色“ AO”,“ RO”,“ TO”和“ AO”。我的互动线代表每个角色的均值。现在,我要添加隆重的中线。我该如何实现? 谢谢!

解决方法

使用lines,在mean中不使用tapply进行交互变量的情况下,应该会为您提供所需的值。 示例:

with(ToothGrowth,interaction.plot(dose,supp,len,fixed=TRUE,legend=F))
lines(with(ToothGrowth,tapply(len,dose,mean)),col=2)
legend("topleft",lty=1:2,col=c(1,1,2),legend=c("OJ","VC","grand mean"),title="supp",bty="n",cex=.9)

enter image description here