Проблема заключается в том, что interaction.plot
фактически использует tapply()
для вычисления агрегированных суммарных показателей (среднее или медианное). Поскольку interaction.plot
просто вызывает matplot
, вы можете использовать последнее напрямую, если хотите, или суммировать свои данные с помощью plyr и отображать результаты с помощью ggplot2 (более гибко).
# consider the 64x4 dataset OrchardSprays and create a fake
# two-levels factor, say grp, which is in correspondence to rowpos odd/even values
grp <- gl(2, 1, 8, labels=letters[1:2])
# the following won't work (due to color recycling)
with(OrchardSprays,
interaction.plot(treatment, rowpos, decrease,
type="b", pch=19, lty=1, col=as.numeric(colpos), legend=F))
# what is used to draw the 8 lines is computed from
with(OrchardSprays,
tapply(decrease, list(treatment=treatment, rowpos=rowpos), mean))
# the following will work, though
with(OrchardSprays,
interaction.plot(treatment, rowpos, decrease,
type="b", pch=19, lty=1, col=as.numeric(grp), legend=F))
Короче говоря, предполагая, что вы можете найти адекватное отображение между gender
и вашим коэффициентом трассировки (age_bucket
), вам нужно построить вектор цветов размером nlevels(age_bucket)
.