数据可视化分析中我们经常需要进行数据间的统计分析,并进行显著性标记,虽然ggpur
包被大佬吐槽制造混乱,但在进行显著性标记标记方面也是有其可取之处。
下面主要展示ggpubr
与ggsignif
包对数据进行统计分析,喜欢的小伙伴可以关注我的公众号R语言数据分析指南
将分享更多实用文档,先行拜谢了
加载R包
library(pacman)
pacman::p_load(tidyverse,ggpubr,rstatix,ggsci,ggsignif,reshape2)
wilcox(秩合检验)
ggplot(iris,aes(Species,Sepal.Length,fill=Species)) +
geom_boxplot()+geom_jitter(shape=16,size=2,position=position_jitter(0.2))+
geom_signif(comparisons = list(c(\"versicolor\", \"virginica\"),
c(\"versicolor\",\"setosa\"),
c(\"virginica\",\"setosa\")),
map_signif_level=T,
textsize=6,test=wilcox.test,step_increase=0.2)+
guides(fill=FALSE)+xlab(NULL)+theme_classic()
![图片[1]-ggplot2添加p值和显著性—科研工具箱-叨客学习资料网](https://cdn.leobba.cn/wp-content/uploads/frc-b146354efdee83008b322e9b446d68aa.png~tplv-vsxgrxnt6c-1.image)
t_test分析
ggplot(iris,aes(Species,Sepal.Length,fill=Species)) +
geom_boxplot()+
scale_fill_jco()+
geom_jitter(shape=16,size=2,position=position_jitter(0.2))+
geom_signif(comparisons = list(c(\"versicolor\", \"virginica\"),
c(\"versicolor\",\"setosa\"),
c(\"virginica\",\"setosa\")),
map_signif_level=T,
textsize=6,test=t.test,step_increase=0.2)+
guides(fill=F)+xlab(NULL)+theme_classic()
![图片[2]-ggplot2添加p值和显著性—科研工具箱-叨客学习资料网](https://cdn.leobba.cn/wp-content/uploads/frc-7c77165d3182b78d6f6deecc6241d6a8.png~tplv-vsxgrxnt6c-1.image)
anova分析
ggplot(iris,aes(Species,Sepal.Length,fill=Species)) +
geom_boxplot()+
scale_fill_jco()+
geom_jitter(shape=16,size=2,position=position_jitter(0.2))+
stat_compare_means(method = \"anova\")+theme_bw()
![图片[3]-ggplot2添加p值和显著性—科研工具箱-叨客学习资料网](https://cdn.leobba.cn/wp-content/uploads/frc-8d8d15e97a3f4975974d9de06d580a80.png~tplv-vsxgrxnt6c-1.image)
kruskal分析
ggplot(iris,aes(Species,Sepal.Length,fill=Species)) +
geom_boxplot()+
scale_fill_jco()+
geom_jitter(shape=16,size=2,position=position_jitter(0.2))+
stat_compare_means()+theme_bw()
![图片[4]-ggplot2添加p值和显著性—科研工具箱-叨客学习资料网](https://cdn.leobba.cn/wp-content/uploads/frc-94918f8439ce2e716cef9a2061f3a24f.png~tplv-vsxgrxnt6c-1.image)
对多组数据进行分面
iris %>% melt() %>%
ggplot(aes(variable,value,fill=Species)) +
geom_boxplot()+
scale_fill_jco()+
stat_compare_means(label = \"p.format\")+
facet_grid(.~variable,scales = \"free\",space=\"free_x\")+
theme_bw()+theme(axis.text.x = element_blank())
![图片[5]-ggplot2添加p值和显著性—科研工具箱-叨客学习资料网](https://cdn.leobba.cn/wp-content/uploads/frc-85c4c06b03aab514b8d643503e186b94.png~tplv-vsxgrxnt6c-1.image)
iris %>% melt() %>%
ggplot(aes(variable,value,fill=Species)) +
geom_boxplot()+
scale_fill_jco()+
stat_compare_means(label = \"p.signif\", label.x = 1.5)+
facet_grid(.~variable,scales = \"free\",space=\"free_x\")+
theme_bw()+theme(axis.text.x = element_blank())
![图片[6]-ggplot2添加p值和显著性—科研工具箱-叨客学习资料网](https://cdn.leobba.cn/wp-content/uploads/frc-a4e7bafe986eac1b5f9d00c0084206d2.png~tplv-vsxgrxnt6c-1.image)
© 版权声明
THE END
暂无评论内容