微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过 ggpubr 将 p 值添加到 100% 堆积条形图

如何解决通过 ggpubr 将 p 值添加到 100% 堆积条形图

所以我制作了一个堆叠条形图,其中 1 - 5 分的数量在堆叠条形图中可视化,在 y 轴上运行到 100%。每个分数都有一个描述,如“非诊断”、“次优”、“足够”、“良好”、“优秀”,在 7 个设置中测量。

此外,我通过 ggpubr 包在参考设置“S2 16ch”和其他设置之间进行了配对测试:

my_comparisons <- compare_means(score ~ Setup,data = df,ref.group = "S2 16ch")

所以我用这样的数据框运行:

df <- data.frame(score = c(1,2,3,5,4,1,1),Setup = c(rep("S2 16ch",4),rep("S2 72ch",rep("S4 72ch",rep("S6 72ch",rep("CS2 72ch",rep("CS4 72ch",rep("CS6 72ch",4)))

table(df)

score CS2 72ch CS4 72ch CS6 72ch S2 16ch S2 72ch S4 72ch S6 72ch
    1        0        1        1       1       0       0       3
    2        2        1        1       2       1       1       0
    3        0        1        1       1       1       1       1
    4        1        0        0       0       1       1       0
    5        1        1        1       0       1       1       0
    

但是,要将其运行到 100% 堆积条形图中,我需要重做此数据框以计算通过每个设置的表(df)确定分数的次数,例如:

Setup <- c(rep("S2 16ch",5),5))
score <- rep(c("Non-diagnostic","Suboptimal","Adequate","Good","Excellent"))
Amount  <- c(1,1)

dataf_scores <- data.frame(Setup,score,Amount)

我可以创建 100% 条形图

#reorder legend lables: specify the factor levels in the order you want
dataf_scores$score <- factor(dataf_scores$score,levels = c("Excellent","Non-diagnostic"))

#reorder x-axis categories.
dataf_scores$Setup <- factor(dataf_scores$Setup,levels = c("S2 16ch","S2 72ch","S4 72ch","S6 72ch","CS2 72ch","CS4 72ch","CS6 72ch"))

#stacked barchart: https://www.r-graph-gallery.com/48-grouped-barplot-with-ggplot2.html                                                                                                                  "CS2 72ch","CS6 72ch"))

ggplot(dataf_scores,aes(fill=score,y=Amount,x=Setup)) + 
  geom_bar(position="fill",stat="identity") +
  labs(x = "",y = "% of total slices") +
  ggtitle("Image scores") +
  scale_y_continuous(labels = function(x) paste0(x*100,"%")) +
  scale_fill_manual(values=c("#117f80","#66ccfe","#aa66ff","#40007f","#ff0166")) +
  

但是当我添加

+ stat_compare_means(comparisons = my_comparisons,label = "p.signif",paired = T) 

添加 p 值,它(显然)确实有效,因为我使用 2 个不同的数据框。

知道怎么做吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。