1

ここに画像の説明を入力してください

a <- structure(list(
  X1 = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L), 
                  .Label = c("V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8"), class = "factor"), 
   X2 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,  2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), 
                    .Label = c("A", "B", "C"), class = "factor"), 
  value = c(0.03508924, 0.03054929, 0.03820896, 0.18207091, 0.25985142, 0.03909991, 0.03079736, 
            0.41436334, 0.02957787, 0.03113289, 0.03239794, 0.1691519, 0.16368845, 0.0287741, 0.02443448, 
            0.33474091, 0.03283068, 0.02668754, 0.03597605, 0.17098721, 0.23048966, 0.0385765, 0.02597068, 0.36917749), 
   se = c(0.003064016, 0.003189752, 0.003301929, 0.006415592, 0.00825635, 0.003479607, 
          0.003195332, 0.008754099, 0.005594554, 0.006840959, 0.006098068, 0.012790908, 0.014176414, 
          0.006249045, 0.005659445, 0.018284739, 0.005051873, 0.004719352, 0.005487301, 0.011454206, 
          0.01290797, 0.005884275, 0.004738851, 0.014075813)), 
  .Names = c("X1", "X2", "value", "se"), class = "data.frame", row.names = c(NA, -24L)) 

上記のデータ(データセット "a"に保持されている)をプロットしていますが、グループチャートの中央に信頼度を置くことができません。これまでの私の試みでは、それぞれの側面に線を引くことしかできませんでした。 geom_errorbarヘルプファイルのように真ん中にはありません。覆い焼きパラメータを操作しようとしましたが、悪化しただけです。チャートは裏返したままにする必要があり、以下のコードではgeom_linerangeを使用しましたが、geom_errorbarの方がさらに優れています。私がうまくできていないもう1つのことは、スケールを整数に変更することです(元のテーブルを多重化することなく)。

以下のコードをa<-a[1:16、](最初の2つのグループ)で使用しました。テーブル全体で同じコードを使用すると、信頼区間でさらに悪い結果が得られます。誰かが助けることができるでしょうか?よろしくお願いします。

limits <- aes(ymax = value + se, ymin=value - se)
 p<-ggplot(data = a, aes(x = X1, y =value))+   
    geom_bar(aes(fill=X2),position = "dodge") +    
    scale_x_discrete(name="")+
    scale_fill_manual(values=c("grey80","black","red"))+
    scale_y_continuous(name="%")+   
    theme(axis.text.y = element_text(face='bold'),
          legend.position ="top",
          legend.title=element_blank())+   
     coord_flip()
p + geom_linerange(limits)
4

1 に答える 1

2

これを試して 、

p<-ggplot(data = df, aes(x = X1, y =value,fill= X2))+   
    geom_bar(position=position_dodge()) +
    geom_errorbar(aes(ymax = value + 2* se, ymin=value,colour = X2),position=position_dodge(.9))



p <- p + scale_x_discrete(name="")+
   scale_fill_manual(values=c("grey80","black","red"))+
   scale_y_continuous(name="%")+   
   theme(axis.text.y = element_text(face='bold'),
         legend.position ="top",
         legend.title=element_blank())+   
   coord_flip()

ここに画像の説明を入力してください

于 2012-11-29T15:34:56.800 に答える