通路分析两组对比横向条形图
2022-04-27 本文已影响0人
yingyonghui
all.path <- all.path[order(all.path$t,decreasing=T),]
all.path$pathway <- stringr::str_to_title(substring(rownames(all.path),10))
all.path$pathway <- gsub(pattern="_", replacement=" ", x=all.path$pathway)
all.path$pathway <- factor(all.path$pathway,levels=rev(all.path$pathway))
num_p_sig <- length(which(all.path$adj.P.Val < 0.05 & all.path$t > 0))
num_n_sig <- length(which(all.path$adj.P.Val < 0.05 & all.path$t < 0))
num_non_sig <- length(which(all.path$adj.P.Val >= 0.05))
all.path$color.bar <- c(rep("firebrick1",num_p_sig),rep(gray(0.5),num_non_sig),rep("steelblue",num_n_sig))
all.path$color.txt <- c(rep("black",num_p_sig),rep(gray(0.5),num_non_sig),rep("black",num_n_sig))
all.path$hjust <- ifelse(all.path$t>0,1,0)
max(all.path$t)
min(all.path$t)
pdf("xxx.pdf",height=10,width=6)
ggplot(all.path,aes(x=pathway,y=t)) +
geom_text(aes(y=0,label=pathway,hjust=hjust),color=all.path$color.txt) +
geom_bar(aes(fill=pathway),stat="identity") +
scale_fill_manual(values=rev(all.path$color.bar)) +
coord_flip() +
theme(legend.position='none') +
labs(x="",y="") +
scale_x_discrete(breaks=NULL) +
scale_y_continuous(limits=c(-25,25))
dev.off()
成图:
WX20220427-110704@2x.png