我正在使用ggplot绘制来自不同组的4周内一组体重数据的平均值的分组条形图。我试图绘制标准错误的误差条,但它们不是在每个条的中心,而是在每个簇的中心。 See picture
我有脚本:
data <- read.table(file="groups.txt",head=TRUE,sep="\t")
attach(data)
melted <- melt(data, id.vars=c("id", "group"))
means <- ddply(melted, c("group", "variable"), summarise,
mean=mean(value))
means.sem <- ddply(melted, c("group", "variable"), summarise,
mean=mean(value), sem=sd(value)/sqrt(length(value)))
means.sem <- transform(means.sem, lower=mean-sem, upper=mean+sem)
m.bp<-ggplot(means, aes(variable, mean)) +
geom_bar(aes(fill = group), position = "dodge", stat="identity") + xlab("Age") + ylab("Weight(g)") + scale_x_discrete(labels=c("w1" = "P7", "w2" = "P14",
"w3" = "P21", "w4" = "P28")) + scale_fill_manual(values = c("orange", "chocolate2", "grey32", "grey25"),name="Genotype\n/Sex", breaks=c("kf", "km", "wf", "wm"),
labels=c("Dlk1 KO Female", "Dlk1 KO Male", "WT Female", "WT Male"))
m.bp + geom_errorbar(aes(ymax=upper,ymin=lower), width=.2, position=position_dodge(0.9),
data=means.sem)
根据年龄,按组对体重数据进行聚类非常有效。但是,当我绘制它时,我的误差条在群集上居中,而不是在每个条上单独。有没有人知道如何让错误条位于正确的位置?