R: 添加显著性标记

2021-08-19  本文已影响0人  胡童远

安装依赖

install.packages("pacman")
library(pacman)
pacman::p_load(tidyverse,ggpubr,rstatix,ggsci,ggsignif,reshape2)

1 输入

2 计算均值,wilcoxon配对检验

bgi = data[data$group=="BGISEQ",]$gc
illu = data[data$group=="Illumina",]$gc
mean(bgi)
mean(illu)
wilcox.test(bgi, illu, paired = TRUE)

3 ggplot绘图

Title = ""
p = ggplot(data, aes(x = group, y = gc/100, color=group)) + 
  labs(x="", y="GC content", title="") +
  theme_classic() +
  geom_boxplot(width=0.5, outlier.colour = NA, lwd = 1) +
  geom_line(aes(group=id), color="gray" ,position = position_dodge(0.2)) +
  geom_point(aes(fill=group, group=id), 
             size = 2, 
             position = position_dodge(0.2)) +
  scale_fill_manual(values = c('orangered3','deepskyblue3')) +
  theme(panel.grid = element_line(colour = 'white')) +
  theme(legend.position="none") +
  theme(axis.title = element_text(size = 30),
        axis.text = element_text(size = 28),
        axis.line = element_line(size = 1),
        axis.ticks = element_line(size = 1),
        title = element_text(size = 20)) +
  scale_y_continuous(labels = scales::percent) +
  geom_signif(comparisons = list(c("BGISEQ", "Illumina")), # 分组
              map_signif_level = T, # T 标记 F 数字
              textsize = 6, 
              annotation = c("NS"),
              color = "black", 
              fontface = "bold",
              size = 1, # 线条粗细
              tip_length = 0.01, # 端点长度
              test = wilcox.test)

geom_signif参数

  geom_signif(comparisons = list(c("BGISEQ", "Illumina")), # 分组
              map_signif_level = T, # T 标记 F 数字
              textsize = 6,  # *标记用12号
              annotation = c("NS"),
              color = "black", 
              fontface = "bold",
              size = 1, # 线条粗细
              tip_length = 0.01, # 端点长度
              test = wilcox.test)

更多:
ggplot2添加p值和显著性
ggplot画标准误条形图加显著性标记
R绘图_ggsignif添加显著性标识

上一篇下一篇

猜你喜欢

热点阅读