前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >小提琴图添加显著性标记(通用版)

小提琴图添加显著性标记(通用版)

作者头像
R语言数据分析指南
发布2024-04-02 12:32:34
950
发布2024-04-02 12:32:34
举报
代码语言:javascript
复制
library(ggtext)
library(tidyverse)
library(ggpubr)
library(rstatix)

df <- read_tsv("data.xls")

df %>% select(Cell_type) %>% group_by(Cell_type) %>%
  mutate(count = n()) %>% distinct()

dff <- df %>%  
  mutate(Cell_type=case_match(Cell_type,"PC3" ~ "PC3<br><br>(n=27)",
                              "HeLa" ~"HeLa<br><br>(n=24)",
                              "K562" ~ "K562<br><br>(n=29)"))

dff$Cell_type <- factor(dff$Cell_type,levels = dff$Cell_type %>% unique())

df_p_val1 <- dff %>% 
  wilcox_test(True_coverage ~ Cell_type) %>%
  adjust_pvalue(p.col = "p", method = "bonferroni") %>%
  add_significance(p.col = "p.adj") %>% 
  add_xy_position(x = "Cell_type",dodge=0.8)

dff %>% ggplot(aes(Cell_type,True_coverage))+
  geom_violin(aes(fill=Cell_type),show.legend = F,alpha=0.5,trim = F)+
  geom_jitter(aes(fill=Cell_type),width = 0.1,alpha=0.1,show.legend = F)+
  geom_boxplot(aes(fill=Cell_type),width=0.2,staplewidth = 0.2,outliers = F,show.legend = F,alpha=1)+
  stat_summary(geom = "point", fun = "mean",color="#CB2314",size=3,show.legend = F)+ 
  geom_text(stat = 'summary', fun = mean,
            aes(label = round(after_stat(y),digits = 2)),
            size = 3.5,nudge_y = 0.4,color="black")+
  stat_pvalue_manual(df_p_val1,label = "p.adj.signif",tip.length = 0.01,
                     label.size=5,hide.ns = T,color="black")+
  scale_fill_manual(values =c("#A195CE","#5171A4","#85D4E3"))+
  labs(x=NULL,y=NULL)+
  theme_classic()+
  theme(axis.text.x=element_markdown(color="black",face="bold"),
        axis.text.y=element_text(color="black",face="bold"))
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2024-03-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 R语言数据分析指南 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档