ggplot2简单实现waterfall柱形图

安装最新版ggplot2,导入数据:

>library(ggplot2)
>data=read.table('clipboard', T, sep="\t")
>data$pathway <- factor(data$pathway, levels=unique(data$pathway)) #固定顺序
配置颜色、对齐方式,绘图
> data$colour <- ifelse(data$count < 0, "downregulate", "upregulate")
> data$hjust <- ifelse(data$count > 0, 1,0)
> ggplot(data, aes(pathway, count, label = pathway,hjust = hjust))
+ geom_text(aes(y = 0,colour = colour)) +geom_bar(stat = "identity",aes(fill = colour))
+ coord_flip() + labs(x = "", y = "") + scale_x_discrete(breaks = NULL, expand=c(0.2, 0)) + ylim(-20, 20)

最终效果

img