其他分享
首页 > 其他分享> > boxplot of peak length 并两两之间显著性比较

boxplot of peak length 并两两之间显著性比较

作者:互联网

setwd('D:\\12_G4NaK_PEG\\02_peak')
library(data.table)
library(ggplot2)
library(ggsignif)
library(ggpubr)

K_PEG <- fread(file="K_PEG_spe.Peak",
               sep="\t", header = F)
Na_PEG <- fread(file="Na_PEG_spe.Peak",
                sep="\t", header = F)
common<-fread(file="K_Na_PEG_Com.Peak",
              sep="\t", header = F)

peak_size <- c(K_PEG$V3 - K_PEG$V2,
               Na_PEG$V3 - Na_PEG$V2,
               common$V3 - common$V2)

peak_from <- rep(c('K+PEG spc',
                   'Na+PEG spc','Common'),
                 times=c(nrow(K_PEG),nrow(Na_PEG),nrow(common)))

peak_df <- data.frame(size=peak_size, from=peak_from)

# compare_means(size~from, data = peak_df,
#               ref.group = ".all.", method = "t.test")
compaired <- list(c("K+PEG spc", "Na+PEG spc"),c("Na+PEG spc","Common"),c("Common","K+PEG spc"))
> head(peak_df)
  size      from
1  226 K+PEG spc
2   83 K+PEG spc
3  303 K+PEG spc
4  472 K+PEG spc
5  200 K+PEG spc
6  200 K+PEG spc
ggplot(peak_df,aes(x=from,y=size,fill=from)) + 
  
  scale_fill_brewer(type="seq",palette="Set1")+
  stat_boxplot(geom ='errorbar', width = 0.3)+
  geom_boxplot(outlier.colour = NA,width = 0.7) +
  guides(fill = guide_legend(title = '')) +
  # scale_y_continuous(breaks=c(log10(100),log10(200),log10(250),log10(300),log10(350),log10(400),log10(1000),log10(1500)),
  #                    labels = c(100,200,250,300,350,400,1000,1500)) +
  coord_cartesian(ylim=c(0,650)) + labs(col="Peak Size") +
  xlab("") + ylab("The Length of G4s (bp)")+theme_bw()+
  # geom_errorbar(stat = "identity",position = "identity")+
  # geom_signif(comparisons = compaired,step_increase = 0.1,map_signif_level = F,test = t.test)+
  # stat_compare_means(label = "p.signif", label.y = c(650,650,650,650,650),
  #                    method = "t.test", ref.group = ".all.")+
  geom_signif(comparisons = compaired,map_signif_level = T,
              y_position = c(500,600,550),test = wilcox.test)+
  stat_compare_means(comparisons=compaired,label = "p.signif", y=600)+ 
  theme(axis.title = element_text(face = "bold",
                                  size = "16",color = "black"),
        axis.text.x = element_text(face = "bold",color = "black",
                                   size = 12,   hjust = 1, vjust = 1,
                                   angle = 45),
        axis.text.y = element_text(face = "bold",size =12,color = "black"),
        legend.text = element_text(size = 10,face = "bold"),
        legend.title = element_text(size = 10,
                                    face = "bold"),
        legend.position = "",
        panel.grid.major.y = element_blank(),
        panel.grid.minor.y = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        plot.title = element_text(lineheight=.8, face="bold", hjust=0.5, size =11),) 

标签:显著性,text,element,length,signif,PEG,log10,boxplot,size
来源: https://blog.csdn.net/weixin_44879403/article/details/114822456