ggplot2 控制 x, y 轴排序

GO Scatter plot

1
2
3
4
5
# 数据读入
df <- read.table('b63c49b49d7ba1e7.xls',header=TRUE,sep="\t",fill=TRUE)
# 提取富集结果前 30 项目进行绘图展示
df <- head(df, 30)
head(df)

default order

1
2
3
4
5
6
# 根据 label 顺序进行排序
gplot(df, aes(rich_factor, Description)) +
geom_point(aes(colour=-log10(qvalue), size=gene_number)) +
scale_colour_gradientn(colours=c('#436EEE','#FF0000'), guide = "colourbar") +
ggtitle("Statistics of Pathway Enrichment") +
xlab("Rich factor") +ylab("")

order labels

1
2
3
4
5
6
7
# 自定义顺序,根据 rich_factor 从大到小顺序排列
df$Description <- factor(df$Description, levels=df$Description[order(df$rich_factor, decreasing=FALSE)])
gplot(df, aes(rich_factor, Description)) +
geom_point(aes(colour=-log10(qvalue), size=gene_number)) +
scale_colour_gradientn(colours=c('#436EEE','#FF0000'), guide = "colourbar") +
ggtitle("Statistics of Pathway Enrichment") +
xlab("Rich factor") +ylab("")

---------本文结束,感谢您的阅读---------