感谢您的回复。我意识到我想要一个条形图而不是直方图。这是我想出的解决方案:
smoke=read.csv("SmokingEffect.csv",header=TRUE)
smokes=subset(smoke,select=c(Age,Smoke,FEV))
library(plyr)
smokesmeans <- ddply(smokes, c("Age","Smoke"), summarize, mean=mean(FEV),
sem=sd(FEV)/sqrt(length(FEV)))
smokesmeans <- transform(smokesmeans, lower=mean-sem, upper=mean+sem)
smokesmeans[,2] <- sapply(smokesmeans[,2], as.character)
library(ggplot2)
plotation <- qplot(x=Age, y=mean, fill=Smoke, data=smokesmeans,
geom="bar",stat="identity",position="dodge",main="distribution of FEV",
ylab="mean FEV")
plotation <- plotation + geom_errorbar(aes(ymax=upper,
ymin=lower), position=position_dodge(0.9), data=smokesmeans)
png(myplot.png)
plotation
dev.off()
输出如下: