2016-04-12 36 views
1

ggplotを使用してデータをRにプロットすると、エラーバーウィスカは表示されません。ウィスカーはなぜ表示されないのですか?R ggplot geom_errorbarにウィスカが表示されない

(geom_errorbarに "data = ..."を指定する必要はありませんが、より小さなデータセットを使用して、より大きなデータセットの上にいくつかの点とそのエラーバーをプロットします。ここではすべてのデータフレームを小さくするだけですが、使用する予定のコードの近くにこのサンプルを保存したいと考えています)。

ありがとう! ショーナ

shapes <- c(1, 19, 15, 1, 0) 
names(shapes) <- levels(smallDF$Treatment) 

p <- ggplot(data=smallDF, aes(x=pNew, y=diff, group=Treatment)) 
p <- p + geom_errorbar(data=smallDF, aes(ymin=diff-se,ymax=diff+se),  
color="black", width=.3, position=position_dodge(.5)) 
p <- p + geom_line(size=.3) 
p <- p + geom_point(data=smallDF, aes(shape=Treatment),fill="white", 
        size=2.5) 
#p <- p + scale_shape_manual(values=c(1, 19, 15, 1, 0)) 
p <- p + scale_shape_manual(values=shapes) 
p <- p + xlab("Pressure (mmHg)") + ylab("delD (mm)") 
p <- p + theme_bw() 
p <- p + theme(
     legend.position="none" 
#  , axis.text.y=element_blank() 
#  , axis.title.y=element_blank() 
     , panel.border=element_blank() 
     , axis.line = element_line(colour = "black") 
     , axis.text.x = element_text(size=10) 
     , axis.text.y = element_text(size=10) 
     , axis.title.x= element_text(size=10) 
     , axis.title.y= element_text(size=10) 
     , strip.text.x = element_text(size = 10) 
     ) 
p 

enter image description here

Treatment step N diff sd se ci predictD pNew 
cntl 2 7 0.256537749 0.130605763 0.049364339 0.120790185 1.483185156 10 
cntl 3 7 0.317586245 0.151444256 0.057240549 0.140062577 1.626590815 15 
cntl 4 7 0.377309785 0.165262839 0.062463482 0.152842634 1.788401781 20 
cntl 5 7 0.433531627 0.173735352 0.065665791 0.160678402 1.964393744 25 
cntl 6 7 0.467529177 0.171603123 0.064859884 0.158706419 2.142879696 30 
cntl 7 7 0.441401156 0.163740786 0.0618882 0.15143497 2.291729181 35 
cntl 8 7 0.360578168 0.143967074 0.054414439 0.133147337 2.402152991 40 
cntl 9 7 0.263484929 0.117425017 0.044382485 0.108600028 2.481824239 45 
cntl 10 7 0.172079736 0.094209661 0.035607905 0.087129405 2.53504158 50 
cntl 11 7 0.081780331 0.070316765 0.026577239 0.065032161 2.561500546 55 
cntl 12 7 0.172079736 0.094209661 0.035607905 0.087129405 2.53504158 50 
cntl 13 7 0.263484929 0.117425017 0.044382485 0.108600028 2.481824239 45 
cntl 14 7 0.360578168 0.143967074 0.054414439 0.133147337 2.402152991 40 
cntl 15 7 0.441401156 0.163740786 0.0618882 0.15143497 2.291729181 35 
cntl 16 7 0.467529177 0.171603123 0.064859884 0.158706419 2.142879696 30 
cntl 17 7 0.433531627 0.173735352 0.065665791 0.160678402 1.964393744 25 
cntl 18 7 0.377309785 0.165262839 0.062463482 0.152842634 1.788401781 20 
cntl 19 7 0.317586245 0.151444256 0.057240549 0.140062577 1.626590815 15 
cntl 20 7 0.256537749 0.130605763 0.049364339 0.120790185 1.483185156 10 
3hpx 2 6 0.124643574 0.068765439 0.028073373 0.072164903 1.511618688 10 
3hpx 3 8 0.121806932 0.088542241 0.03130441 0.074023166 1.537544183 15 
3hpx 4 8 0.138107729 0.097228081 0.034375318 0.08128471 1.602344034 20 
3hpx 5 8 0.149529 0.10158369 0.035915258 0.08492609 1.665227481 25 
3hpx 6 8 0.157687817 0.101898303 0.036026491 0.085189113 1.724788023 30 
3hpx 7 8 0.154261671 0.099724849 0.035258058 0.08337206 1.776475381 35 
3hpx 8 8 0.140631071 0.091483297 0.03234423 0.07648195 1.819131367 40 
3hpx 9 8 0.123241311 0.083112381 0.029384664 0.069483689 1.854326249 45 
3hpx 10 8 0.103092334 0.075467614 0.026681831 0.063092504 1.882440312 50 
3hpx 11 8 0.080332775 0.070303352 0.024855989 0.058775073 1.903587298 55 
3hpx 12 8 0.103092334 0.075467614 0.026681831 0.063092504 1.882440312 50 
3hpx 13 8 0.123241311 0.083112381 0.029384664 0.069483689 1.854326249 45 
3hpx 14 8 0.140631071 0.091483297 0.03234423 0.07648195 1.819131367 40 
3hpx 15 8 0.154261671 0.099724849 0.035258058 0.08337206 1.776475381 35 
3hpx 16 8 0.157687817 0.101898303 0.036026491 0.085189113 1.724788023 30 
3hpx 17 8 0.149529 0.10158369 0.035915258 0.08492609 1.665227481 25 
3hpx 18 8 0.138107729 0.097228081 0.034375318 0.08128471 1.602344034 20 
3hpx 19 8 0.121806932 0.088542241 0.03130441 0.074023166 1.537544183 15 
3hpx 20 6 0.124643574 0.068765439 0.028073373 0.072164903 1.511618688 10 
+1

ウィスカーが、そこだけは本当に小さいです。 'width = 0.3'の設定を大きくしてみてください。また、ここで 'position_dodge'を使用する理由はありますか? – fanli

+0

Fanli、サイズを増やしてみましたが、同じ出力が得られます。これはパネルBであり、パネルAはエラーバーの幅= .3にひげがあり、それらを同じにしたい。私はposition_dodgeを使って、欠けているウィスカーの修正を見つけようと試みましたが、私のプロットには必要ありません。ああ、実際のデータベースははるかに大きく(5つの曲線)、多くのgeom_pointと誤差バーが重なります。 – Shawna

+0

エラーバーの幅が違う別のパネル(ファセットを意味しますか?)がある場合、それはあなたの質問にかなり関係しているようです。 – Gregor

答えて

1

私はwidth = 5にごwidth = 0.3を変更しました。また、base_sizeの引数がtheme_bw()の個別のフォントサイズを置き換えた冗長data = smallDFをすべて削除しました。

p <- ggplot(data = smallDF, aes(x = pNew, y = diff, group = Treatment)) + 
    geom_errorbar(aes(ymin = diff - se, ymax = diff + se),  
       color = "black", 
       width = 5, ## This is the width of the crossbars! 
       position = position_dodge(.5)) 
    geom_line(size = .3) 
    geom_point(aes(shape = Treatment), 
      fill = "white", size = 2.5) + 
    scale_shape_manual(values = shapes) + 
    xlab("Pressure (mmHg)") + 
    ylab("delD (mm)") + 
    theme_bw(base_size = 10) + 
    theme(
     legend.position="none" 
     , panel.border=element_blank() 
     , axis.line = element_line(colour = "black") 
) 
p 

enter image description here

+0

GregorとFanliに感謝します。 – Shawna

関連する問題