# how to build a barplot of means by condition, together with standard error bars
dat <- read.delim("results.final.txt")
dat1 <- subset(dat,crit=="RC_VERB+1" & expt==1)
dat1$cond <- factor(dat1$cond)
# first, aggregate across items to create a table of means per condition per subject
# tapply() is really useful for this
means.per.subject <- with(dat1,tapply(rt,list(subj,cond),mean))
# now, calculate the means and standard errors of these means
# apply() is really useful for this
means <- apply(means.per.subject,2,mean)
se <- function(x) sd(x)/sqrt(length(x))
ses <- apply(means.per.subject,2,se)
# use barplot() to construct the initial barplot
# explicitly set width and space params so you know where to put the standard error bars
barplot(means,names.arg=names(means),ylim=c(400,600),xpd=F,col=c("blue","magenta","gray","yellow"), width=0.8,space=0.25)
# the trick is getting the standard error bars. Use arrows() to do this.
# code=3 means that the arrows point both ways
# angle=90 means that the heads of the arrows are flat
x.positions <- 1:4 - 0.4
arrows(x.positions,means-ses,x.positions,means+ses, code=3,angle=90)
# in addition, there are lots of other graphics parameters that can be used with barplot; do help(par) to read about these.