2019-08-06用ggplot2绘制两侧柱状图
2019-08-06 本文已影响1人
iColors
1、首先构建一个虚拟的数据
df <-data.frame(gene=paste("gene",c(1:10)),exp=c(1,-1,2,-2,2,-3,4,5,-5,6))
2、绘制基本图形
library(ggplot2)
ggplot(df,aes(x = gene,
y=exp,
fill = gene,
label = exp))+
geom_col(show.legend = FALSE) +
xlab('Gene Name') +
ggtitle('Expression level of significant changed genes')
image.png
3、不好看😝,调整一下坐标轴
ggplot(df,aes(x = gene,
y=exp,
fill = gene,
label = exp))+
geom_col(show.legend = FALSE) +
coord_flip() +
xlab('Gene Name') +
ggtitle('Expression level of significant changed genes')
image.png
4、好多了,再改改排列顺序
ggplot(df,aes(x = reorder(gene,exp),y=exp,
fill = gene,
label = exp))+
geom_col(show.legend = FALSE) +
coord_flip() +
xlab('Gene Name') +
ggtitle('Expression level of significant changed genes')
image.png
5、还差点什么,对了,把数字标注到柱子上
ggplot(df,aes(x = reorder(gene,exp),y=exp,
fill = gene,
label = exp))+
geom_col(show.legend = FALSE) +
coord_flip() +
geom_text(nudge_x = 0.1) +
xlab('Gene Name') +
ggtitle('Expression level of significant changed genes')
image.png
6、最后用ggtheme美颜一下,齐活!
library(ggthemes)
ggplot(df,aes(x = reorder(gene,exp),y=exp,
fill = gene,
label = exp))+
geom_col(show.legend = FALSE) +
coord_flip() +
geom_text(nudge_x = 0.1) +
xlab('Gene Name') +
ggtitle('Expression level of significant changed genes')+
theme_clean()
image.png