2016-12-29 9 views
1

私は10個のビンに渡って時系列データを平均化しようとしており、ビン平均化プロットをプロットしています。ggplot2のエラーバーstat_summary_bin

ggplot2を使用すると、どのようにエラーバーをstat_summary_bin()にオーバーレイできますか?ここで

は、私が試したものです:

# My data 
load("xyz.Rdata") 

str(df) 
# data.frame': 125 obs. of 3 variables: 
# $ xdata : num -0.0209 -0.04 1.4145 0.7419 0.9393 ... 
# $ ydata : num -19.78 -23.29 8.86 16.04 11.65 ... 
# $ ir.fac: Factor w/ 3 levels "irh","irl","irm": 2 2 3 3 3 1 3 3 3 2 ... 

# Graph 
ggplot(df) + 
stat_summary_bin(aes(x = xdata, y = ydata, color= ir.fac), 
       fun.y = "mean", 
       bins= 10, size= 0.5, 
       geom= 'line') + 
stat_summary_bin(aes(x = xdata, y = ydata, color = ir.fac), 
       fun.y = "mean", 
       bins= 10, size= 2, 
       geom= "point") 
+2

コードを実行できるように、例を再現可能にしてください。 – eipi10

+1

'fun.data = mean_se'はあなたが探している出力を与えますか? – eipi10

+0

いいえ、data = mean_seはエラーをスローします。 – ram

答えて

1

ここでは、組み込みのirisデータフレームを使用した例です。 fun.data=mean_seは、デフォルトで+/- 1標準誤差に等しい誤差バーを持つ点を与えます。これを1.96標準エラーに変更するには、fun.args=list(mult=1.96)stat_summary_binに追加します。

library(ggplot2) 
theme_set(theme_classic()) 

pd=position_dodge(0.07) 

ggplot(iris) + 
    stat_summary_bin(aes(x = Sepal.Width, y = Sepal.Length, color= Species), 
        fun.y = "mean", position=pd, 
        bins= 10, size=0.8, 
        geom= "line") + 
    stat_summary_bin(aes(x = Sepal.Width, y = Sepal.Length, color= Species), 
        fun.data = mean_se, position=pd, 
        bins= 10, size= 0.4) 

enter image description here

あなたの代わりに、古典的な標準誤差のブートストラップ信頼区間をしたい場合は、デフォルトで95%CIを与えるであろう、代わりにfun.data=mean_sefun.data=mean_cl_bootを使用することができます。

+0

ありがとうeipi10、助けていただきありがとうございます – ram

関連する問題