2016-09-01 4 views
6

私の目標は、Rでボックスプランを作成することです(これはggplot2で行う必要はありませんが、私が今使っていることです)マイナステキスト):ここでggplot2のエラーバーからエンドポイントを削除する

boxplot-example

は、私がこれまで持っているコードです:

my-boxplot:その結果

dat <- read.table(file = "https://www.dropbox.com/s/b59b03rc8erea5d/dat.txt?dl=1", header = TRUE, sep = " ") 
library(ggplot2) 
p <- ggplot(dat, aes(x = Subscale, y = Score, fill = Class)) 
p + stat_boxplot(geom = "errorbar", width = 1.2, size = 2.5, color = "#0077B3") + 
    geom_boxplot(outlier.shape = NA, coef = 0, position = position_dodge(.9)) + 
    scale_fill_manual(values = c("#66CCFF", "#E6E6E6")) + 
    theme(panel.background = element_rect(fill = "white", color = "white")) 

明らかに、私が持っているものと実際の例の違いはたくさんありますが、今はエラーバーからエンドポイントを削除することに集中しています。 stat_boxplot機能です。誰も私が望む効果を得る方法を知っていますか?

答えて

5

errorbar geomのは、水平エンドバーの幅を制御するため、0に設定してエンドバーを削除します。 stat_boxplotレイヤーで覆われていないので、これを追加してエラーバーを正しく取り除くことができます。

ggplot(dat, aes(x = Subscale, y = Score, fill = Class)) + 
    stat_boxplot(geom = "errorbar", width = 0, size = 2.5, 
       color = "#0077B3", position = position_dodge(.9)) + 
    geom_boxplot(outlier.shape = NA, coef = 0, position = position_dodge(.9)) + 
    scale_fill_manual(values = c("#66CCFF", "#E6E6E6")) + 
    theme(panel.background = element_rect(fill = "white", color = "white")) 

enter image description here

+0

うわー、私はそれが簡単だろうとは思いませんでした!どうもありがとうございます!私はwidthプロパティが完全に何か他のことをしていると思った。 – psychometriko

関連する問題