1. 效果图
2. 代码
# 生成测试数据
dif=data.frame(labels=paste0("pathway", 1:3),up=c(30,15,1),down=c(10,20,40)
)
rownames(dif)=dif$labels
dif#变形
dif=reshape2::melt(dif)
dif# 绘图
ggplot(dif, aes(x=labels, y=ifelse(variable=="up", value, -value), fill=variable ) )+geom_bar(stat="identity")+geom_text(aes(label=value,vjust=ifelse(variable=="up", -0.4, 1.1), #调整上下数字的位置坐标),size=4 #number font size)+scale_fill_manual(name="Change", values = c("#ae3137", "#497aa2"),breaks = c("up", "down"), #原始图例标签labels = c("lengthen", "shorten"), #新图例标签)+scale_y_continuous(labels=abs, #y轴 显示绝对值expand=expansion(mult=c(0.1, 0.1)))+labs(x="", y="Gene number", title="compare result")+theme_classic(base_size = 12)+theme(axis.text.x = element_text(angle = 60, hjust = 1, size=12),axis.text.y = element_text(size=12),)
3. todo
-
继续优化显示效果
-
整理到我的实例笔记 http://tool.dawneve.com/R_scripts/index.html
-
https://zhuanlan.zhihu.com/p/445273345