Reputation: 497
I am using ggplot2 to make bar plots of some Gene Ontology data. Basically, I had a list of proteins, and the GO interface allows me to see which pathways those proteins intervene in. I'm plotting significance on the Y axis (as -log(pval)
), and I'd like to have the name of each pathway shown on the barplot, sort of like this:
head(pathways_filt)
GO_biological_process_complete qval log.qval process
32508 DNA duplex unwinding 5.33e-08 7.273273 DDR
32392 DNA geometric change 9.38e-08 7.027797 DDR
6302 double-strand break repair 2.08e-07 6.681937 DDR
6396 RNA processing 1.80e-06 5.744727 RNA
71103 DNA conformation change 9.93e-06 5.003051 DDR
6281 DNA repair 1.18e-05 4.928118 DDR
pdf(paste0(godir, "barplot_Pich_Tat_qval_DDR_RNA.pdf"))
ggplot(pathways_filt, aes(x=reorder(row.names(pathways_filt), -log.qval), y=log.qval, fill=process)) +
geom_bar(stat="identity") +
geom_text(data = pathways_filt, mapping=aes(x=reorder(row.names(pathways_filt), -log.qval), label=GO_biological_process_complete), size=3, angle=90, hjust="top") +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
dev.off()
However, the pathway description overflows "below" the plot. I'd prefer if it overflowed above each bar, so that it would be fully readable.
Is there any way to align these labels to the x axis?
Upvotes: 0
Views: 221
Reputation: 1252
The geom_text()
uses also the y =
aesthetics, therefore the text is printed at the top of the bars. Suggest you override this by changing the geom_text()
as follows:
geom_text(data = pathways_filt, mapping=aes(y = 0, x=reorder(row.names(pathways_filt), -log.qval), label=GO_biological_process_complete), size=3, angle=90, hjust="bottom")
Upvotes: 2