我有一個看起來像這樣的數據:如何繪製ggplot2(R)中的多組平均值和置信區間?
A B C
8 5 2
9 3 1
1 2 3
3 1 2
4 3 1
我需要繪製每個這些手段用GGPLOT2置信區間一起。我也想從數據iteself中獲得置信區間(例如,使用stat_summary(fun.data = mean_cl),但是我不確定如何繪製這種格式的數據的手段。 。下面的代碼,但它不跑,我不知道什麼需要進入在y在第2行
pd <- position_dodge(0.78)
ggplot(dat, y = c(dat$A,dat$B,dat$C) + ylim(0,10) + theme_bw()) +
stat_summary(geom="bar", fun.y=mean, position = "dodge") +
stat_summary(geom="errorbar", fun.data=mean_cl_normal, position = pd)
我得到以下錯誤:
Warning messages:
1: Computation failed in `stat_summary()`:
object 'x' not found
2: Computation failed in `stat_summary()`:
object 'x' not found
我已經更新了我的答案 – BioBuilder
你似乎缺少a)ggplot()..也請通過消除所有主題等使這個最小的可重複的例子。還有什麼版本的ggplot2你? – Elin
@Elin:我做了更新。我正在使用ggplot2 2.1.0 – BioBuilder