分面boxplot

setwd('D:\\11_NM_DNAmeth\\02_DMs_DMR\\01_hyper_hypo')
library(ggplot2)
library(ggsignif)
library(ggpubr)
data<-read.table('./DMR_hyp_methLevel.txt',header = 0)

colnames(data)<-c('sample','sample2','level','type','value')
table(data$sample2)
table(data$type)
data$sample<- factor(data$sample,
                     levels= c('BCD',"CK"),ordered = TRUE)

# compare_means(log2TPM~sample, data=data, group.by = "type",method = "wilcox.test" )
> head(data)
  sample  sample2     level type      value
1    BCD BCD_rep1 DMR_hyper    C 0.04511278
2    BCD BCD_rep1 DMR_hyper    C 0.04615385
3    BCD BCD_rep1 DMR_hyper    C 0.13785733
4    BCD BCD_rep1 DMR_hyper    C 0.10303030
5    BCD BCD_rep1 DMR_hyper    C 0.11821086
6    BCD BCD_rep1 DMR_hyper    C 0.10126582
ggplot(data,aes(x=sample2,y=value)) + 
  stat_boxplot(geom ='errorbar', width = 0.4)+#aes(colour = sample),
  # geom_violin(trim=FALSE,color="white") +
  geom_boxplot(position=position_dodge(0.9),aes(fill=factor(sample)),
               outlier.alpha=0.05, lwd=0.8,#
               width=0.6,outlier.colour = NA)+#
  # coord_cartesian(ylim=c(0,7)) +
  facet_grid(level~type)+
  # stat_compare_means(label = "p.signif", 
  #                    label.x = 1.5,label.y = 6)+
  labs(title = "") +
  xlab("") + ylab("Methylation Level")+
  theme_classic()+
  scale_fill_brewer(type="seq",palette="Set2")+
  # scale_fill_brewer(palette = "Blues")+
  guides(fill = guide_legend(title = '')) +
  theme(strip.text.x = element_text( colour = 'black',size = 13),#size=8,angle=75
        strip.text.y = element_text( colour = 'black',size = 13),
        strip.background = element_rect(colour="white", fill="grey"),
        axis.title = element_text(face = "bold",
                                  size = "16",color = "black"),
        axis.text.x = element_text(face = "bold",color = "black",angle = 45,
                                   size = 12,  hjust = 1, vjust = 1),
        axis.text.y = element_text(face = "bold",size = 12,color = "black"),
        legend.text = element_text(size = 12,face = "bold"),
        legend.title = element_text(size = 12,
                                    face = "bold"),
        legend.position ='',
        # legend.key.size = 
        panel.grid.major.y = element_blank(),
        panel.grid.minor.y = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        # axis.text.x=element_blank(),
        # axis.ticks.x=element_blank(),
        # axis.line = element_line(size=1, colour = "black"),
        axis.ticks = element_line(size = 1),
        # panel.border = element_rect(colour = "black", fill=NA, size=1.5),
        # panel.border = element_blank(),
        axis.line = element_line(size=1, colour = "black"),
        # axis.line = element_line(size=2, colour = "black"),
        plot.title = element_text(lineheight=.8, face="bold", hjust=0.5, size =16)) 

输出结果在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值