2017-07-12 25 views
0

グラフの上部と2つのバープロットの間にp値を注釈することができるかどうかを知りたいと思います。私の場合、ggplot2を使用して、2つの条件(PassageとIsolated)を持つファセットグラフがあり、各条件に3つのレベル/ 3つの棒グラフ(GA、CH、KO)があります。可能であれば、グラフ自体に表示したいペアワイズ比較(GA vs CH、CH vs KO、GA vs KO)のp値があります。Rの面取りバープロットにp値を注釈するにはどうすればよいですか?

マイggplotスクリプトは以下の通りです:

#plot 
dev.new() 
accentrating_comb <- ggplot(ch_ko_am_comb, aes(x=speaker_type, y=Mean, fill=speaker_type)) + 
    geom_bar(position=position_dodge(width=1), stat="identity", colour="black", size=.5) + 
    geom_errorbar(aes(ymin=cllo, ymax=clup), colour="black", size=.3, width=.2, position=position_dodge(width=1)) + 
    geom_text(aes(label=lable), colour="black", vjust=-0.5, size=10, hjust=-2) + 
    coord_cartesian(ylim=c(0,10)) + 
    ylab("Mean Accent Rating") + 
    scale_fill_brewer(type = "div", palette = "Greys") + 
    guides(fill=guide_legend("Accent")) + 
    theme_bw() + 
    theme(plot.title = element_text(size = 22), axis.title.x = element_blank(), axis.title.y = element_text(size = 14), axis.line = element_line(colour = "black"), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), strip.text.x = element_text(size = 14), axis.text.x = element_text(size=14), legend.title=element_text(size=14), legend.text=element_text(size=14), panel.margin.x=unit(20,"pt")) + 
    facet_wrap(~ condition) #this creates multiple panels 
print(accentrating_comb) 
#dev.off() 
+0

'ggsignif'パッケージを試してみてください:https://cran.r-project.org/web/packages/ggsignif/vignettes/intro.html – Marius

+0

あなたが持つプロットにテキストを追加することができますgeom_text –

+0

実際のp値や重要な違いを示す文字を表示しますか? –

答えて

0

あなたの(2つのファセット、それぞれに3つの変数)と同様のプロットを生成するために、私はirisToothGrowthデータセットを使用してダミーのデータセットを作成しました。

この解決策では、ggsignifパッケージを使用してプロットファセットにp値を注釈し、必要に応じて接頭辞p=を追加する方法を示します。

library(ggplot2) 
library(ggsignif) 

data("ToothGrowth") 
data('iris') 

iris2<-iris[c(1:10,50:60,100:110,61:70,11:20,111:118),] 

big_data<-cbind(iris2,ToothGrowth) #dummy data 


plot<-ggplot(big_data, aes(Species, len)) + 
    geom_boxplot() + 
    geom_signif(comparisons =list(c("setosa", "virginica"),c('setosa','versicolor'),c('virginica','versicolor')), 
       step_increase = 0.1)+ 
    facet_wrap(~supp) #create initial plot 

pg<-ggplot_build(plot) #disassemble plot and obtain information 

pv<-pg$data[[2]]$annotation #seek out p values 

new<-as.factor(paste('p=',pv)) #add the desired prefix 

pg$data[[2]]$annotation<-new #swap out the original annotation 

q<-ggplot_gtable(pg) #reassemble the plot 

plot(q) #generate new plot 

enter image description here

+0

こんにちはJ.Con。ありがとう!それは私が探していたものに近いものです。 (私は各面に3つの棒グラフを持つ2つのファセットしか持たないことを除いて)。代わりに、たとえばp = 0.0023というラベルを付けることができる方法はありますか? また、ggsignifパッケージを再インストールしても、「StatSignifという統計情報がありません」というエラーが表示され続けます。 – MZZ

+0

興味深い。プロットやエラーだけがありますか?私は明日見えるだろう。 Cheers –

+0

@Mazについては、 'p ='接頭辞の更新を参照してください。あなたの 'ggplot2'パッケージを更新して、エラーを取り除くことをお勧めします。 –

関連する問題