TVP

# 多组差异分析的可视化，这样做最省心！

7470

``````> library(ggpubr)

Want to understand how all the pieces fit together? Read R for Data
> data("ToothGrowth")
> df <- ToothGrowth
len supp dose
1  4.2   VC  0.5
2 11.5   VC  0.5
3  7.3   VC  0.5
4  5.8   VC  0.5
> ggviolin(df, x = "dose", y = "len", fill = "dose",add = "boxplot", add.params = list(fill = "white"))``````

``````+   df, x = "dose", y = "len",
+   fill = "dose",
+   add.params = list(fill = "white")) +
+ stat_compare_means()``````

stat_compare_means函数添加差异分析的p值，默认参数的情况下，添加组间kw检验的结果，效果图如下

``````> ggviolin(
+   df, x = "dose", y = "len",
+   fill = "dose",
+   add.params = list(fill = "white")) +
+ stat_compare_means(comparisons = list(c("0.5", "1")))``````

``````> ggviolin(
+   df, x = "dose", y = "len",
+   fill = "dose",
+   add.params = list(fill = "white")) +
+ stat_compare_means(comparisons = list(c("0.5", "1"))) +
+ stat_compare_means(comparisons = list(c("1", "2"))) +
+ stat_compare_means(comparisons = list(c("0.5", "2")))``````

``````> ggviolin(
+   df, x = "dose", y = "len",
+   fill = "dose",
+   add.params = list(fill = "white")) +
+ stat_compare_means(comparisons = list( c("0.5", "1"), c("1", "2"), c("0.5", "2") ))``````

``````> ggviolin(
+   df, x = "dose", y = "len",
+   fill = "dose",
+   add.params = list(fill = "white")) +
+ stat_compare_means(
+   label = "p.signif",
+   comparisons = list( c("0.5", "1"), c("1", "2"), c("0.5", "2"))
+ )``````

``````> comparisons <- list( c("0.5", "1"), c("1", "2"), c("0.5", "2") )
> ggviolin(
+   df, x = "dose", y = "len", fill = "dose",
+   palette = c("#00AFBB", "#E7B800", "#FC4E07"),
+   stat_compare_means(comparisons = my_comparisons, label = "p.signif") +
+   stat_compare_means(label.y = 50)``````

·end·

0 条评论