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))
输出结果