2017-06-09 28 views
0

初めてのポスターはここにあります。下に描かれている問題の解決のためにサイト(および他の人)を掃除していた。私はここで、そして他の場所で遭遇した同様の問題に対するさまざまな解決策を試すにもかかわらず、エラーバーを「低い」位置から移動することはできません。ggplot2棒グラフでエラーバーが低すぎる

enter image description here

の問題は、私は1つだけで、グラフまたは2を生成し、gridExtraでそれらを結合するかどうか発生します。ここ

コードと各データセットのサンプルが含まれる:

まずデータセット例:第

Group  PSQI Time_Point 
1 Control 2 Baseline 
2 Control 2 Baseline 
3 Control 2 Baseline 
4 Control 13 Baseline 
5 Control 1 Baseline 
6 Control 7 Baseline 

Group ESS Time_Point 
1 Control 3 Baseline 
2 Control 4 Baseline 
3 Control 1 Baseline 
4 Control 0 Baseline 
5 Control 7 Baseline 
6 Control 11 Baseline 

コード:

library(gridExtra) 
library(ggplot2) 
library(grid) 

p1 <- ggplot(PSQI_Graph,aes(fill=Group,y=PSQI,x=Time_Point)) + 
    geom_bar(position="dodge",stat="identity", width = 0.50) + 
    stat_summary(fun.data = mean_cl_normal, geom = "errorbar", position = 
position_dodge(.5), width = .25)+ 
    guides(fill = F)+ 
    scale_y_continuous(name = "Mean PSQI Score", limits=c(0,25))+ 
    xlab("Time Point") + 
    guides(fill = guide_legend(keywidth = 1.5, keyheight = 1))+ 
    theme_bw() 

なります本当に好きですこのデータを入手してください。そうすれば、どんな提案もありがたいです。

+0

ようこそSOへ:

ggplot(psqi, aes(fill=Group, y=PSQI, x=Time_Point, ymin=PSQI-StdErr, ymax=PSQI+StdErr)) + #the ymin and ymax parameters here tell it where to put the top and bottom error bars geom_bar(stat="identity") + geom_errorbar() #you can change the width and thickness of the bars 

このイメージを得ました。質問を編集して問題を紹介し、準備が整った[再現可能な例](https://cran.r-project.org/web/packages/reprex/README.html#what-is-a-reprex)を提供してください新しいRセッションでコピー・ペーストを実行する。 – lukeA

+0

各ファセットの両方のレベルの平均値を計算すると、誤差バーの中心が平均値のところで正しいことがわかります。 –

答えて

2

geom_errorbarを使用する方がよいでしょう。まず、あなたは標準誤差を含む小節ごとに1行、で新しいdata.frameを作成する必要があります(私はこれがどのように見えるかを示すために時点「後」を追加):

次に
Group PSQI Time_Point StdErr 
1 Control 4.50 Baseline 1.91 
2 Control 7.17  After 0.79 

、このggplot呼び出しが動作します:

+0

完璧に作業しました!伝説! –

関連する問題