2012-12-20 6 views
8

異なる外観のラベルを追加してboxplotを作成したいと思います。期待される(完全ではない)出力は次のようになります(すべてのボックスには四角いラベルがあります)とサンプルサイズ。boxplotのレイアウトを変更してラベルを追加する

enter image description here

boxplot(len~supp*dose, data=ToothGrowth, notch=TRUE, 
    col=(c("gold","darkgreen")), 
    main="Tooth Growth", xlab="Suppliment and Dose", names = supp) 

    # some unsuccessful trials 
# to add names 
boxplot(len~supp*dose, data=ToothGrowth, notch=TRUE, 
    col=(c("gold","darkgreen")), 
    main="Tooth Growth", xlab="Suppliment and Dose", names = supp*dose) 
# to remove the plot outline 
boxplot(len~supp*dose, data=ToothGrowth, notch=TRUE, 
    col=(c("gold","darkgreen")), 
    main="Tooth Growth", xlab="Suppliment and Dose", bty="n") 

答えて

9

これはあなたが始める必要があります。キーは、plot = FALSEを設定している間にオブジェクトにboxplotの結果を保存すると、それぞれのオブジェクトがどこに行くのかについてのすべての情報が得られることを知ることです。次に、この情報を使ってtextでテキストを追加することができます。

d <- boxplot(len~supp*dose, data=ToothGrowth,plot = FALSE) 

boxplot(len~supp*dose, data=ToothGrowth, notch=TRUE, 
    col=(c("gold","darkgreen")), 
    main="Tooth Growth", xlab="Suppliment and Dose",axes = FALSE) 

for (i in 1:ncol(d$stats)){ 
    text(i,d$stats[,i],labels = d$stats[,i],cex = 0.75,adj = c(0.5,0)) 
    text(i,d$stats[5,i]+1,labels = paste0("n=",d$n[i]),cex = 0.75) 
    text(i-0.25,d$stats[3,i],labels = d$names[i],adj = 1,cex = 0.75) 
} 

私は、しかし、誰があなたのことを示唆していることを指摘します:

分位数の値とサンプルサイズで軸

  • 注釈各箱ひげ図を削除すべきでありません誰もがグラフを作ることについてアドバイスをしてください。これまで彼らはあなたの箱のプロットを、はるかに悪化させました。

    enter image description here

  • +3

    おかげで、私は私があなたのメッセージを渡すことがしたい - (!オーダー)いつか私は、このような提案を得る、私は従う必要があります! – shNIL

    関連する問題