data(simdat)
subj.dat <- with(simdat,
aggregate(Y, list(Group=Group, Condition=Condition, Subject=Subject),
mean))
avg <- with(subj.dat, tapply(x, list(Group, Condition), mean))
ses <- with(subj.dat, tapply(x, list(Group, Condition), se))
# barplot:
b <- barplot(avg, beside=TRUE, col=c("gray", "forestgreen"),
main="Average Y", xlab="Condition",
legend.text=c("Adults", "Children"), args.legend=list(x="topleft"))
errorBars(b, avg, 1.96*ses, xpd=TRUE, length=.05)
# line plot:
miny <- with(subj.dat, tapply(x, list(Group, Condition), min))
maxy <- with(subj.dat, tapply(x, list(Group, Condition), max))
emptyPlot(c(-1,4), range(avg),
main="Average Y", xlab="Condition")
group <- "Children"
errorBars(-1:4, avg[group,], maxy[group,], miny[group,], length=.05,
col="forestgreen", lwd=2)
points(-1:4, avg[group,], pch=21, type='o', lty=3, lwd=2,
col="forestgreen", bg="white", xpd=TRUE)
# also horizontal bars possible:
errorBars(10, 1, 1.2, horiz=TRUE)
Run the code above in your browser using DataLab