输入1:
代码语言:javascript复制longrma <- read.csv("longrma.csv",header=T)
longrma[sample(nrow(longrma),,replace=F),]
结果1:
代码语言:javascript复制 id group time score
treatment after
treatment after
control before
control after
treatment before
treatment middle
treatment after
control before
treatment before
control middle
输入2:
代码语言:javascript复制longrma$group <- factor(longrma$group,levels = c("control","treatment"))
longrma$time <- factor(longrma$time,levels = c("before","middle","after"))
install.packages(epiDisplay)
library(epiDisplay)
attach(longrma)
aggregate.plot(x=score,by=list(group=group,time=time), FUN="mean",error="ci",
lwd=, line.col = "black",alpha=0.05,
legend.site = "topleft", bar.col = c("red","blue"))
结果2:
代码语言:javascript复制
输入3:
代码语言:javascript复制longrma$time <- ifelse(longrma$time=="before",, ifelse(longrma$time=="middle",,))
longrma$time <- as.numeric(longrma$time)
attach(longrma)
aggregate.plot(x=score,by=time,grouping=group,FUN="mean",error="ci",
lwd=,line.col=c("black","red"))
detach(longrma)
When 'by' is of class 'factor', a bar plot with error bars is displayed. When 'by' is a continuous variable (typically implying time), a time line graph is displayed.