简体   繁体   中英

Align labels on data points to x axis

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?

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM