如果我有一些数据并进行方差分析和事后测试,我如何制作一个自动添加事后分类的箱线图,而不必在 R 之外编辑图形?
例如,以下是一些入门数据:
install.packages("reshape", dependencies=T)
library(reshape)
x <- rnorm(30)
y <- rnorm(30)+1
z <- rnorm(30)+0.5
data.1 <- data.frame(x, y, z)
data.2 <- melt(data.1)
这是运行简单单向方差分析和所有计划外比较事后测试的代码:
linear.model <- lm(value~variable, data=data.2)
anova(linear.model)
# Analysis of Variance Table
# Response: value
# Df Sum Sq Mean Sq F value Pr(>F)
# variable 2 10.942 5.4710 5.8628 0.004087 **
# Residuals 87 81.185 0.9332
TukeyHSD(aov(linear.model))
# Tukey multiple comparisons of means
# 95% family-wise confidence level
# Fit: aov(formula = linear.model)
# $variable
# diff lwr upr p adj
# y-x 0.8344105 0.2396705 1.42915051 0.0034468
# z-x 0.2593612 -0.3353788 0.85410126 0.5539050
# z-y -0.5750493 -1.1697893 0.01969078 0.0602975
此时,我想将 x 归入“a”组,将 y 归入“b”组,将 z 归入“a,b”组。我可以制作箱线图,但你如何用字母注释它?
boxplot(value~variable, data=data.2)