Question: Barplot labeling squeezed the bars
0
gravatar for Kyle
9 days ago by
Kyle80
Chicago, IL
Kyle80 wrote:

I am trying to make a horizontal barplot in ggplot2. I almost get there but still not satisfied the output. My code is

David_BP_combined_signifcant$Term <- factor(David_BP_combined_signifcant$Term, levels = David_BP_combined_signifcant$Term[order(David_BP_combined_signifcant$logPvalue)]) 

ggplot(David_BP_combined_signifcant, aes(x=Term, y=logPvalue)) + 
          geom_bar(position = 'identity', stat='identity', fill='red')  +
          geom_text(aes(label=Count), size = 2, position=position_stack(vjust=0.5), hjust=0.5) +
          theme_bw() +
          theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
          theme(panel.border = element_blank()) +
          coord_flip() +
          ggsave("FigureC2.tiff", width=6, height=8, dpi=300)

In the output figure the bars are too short, because the labeling of one term is too long. I have tried to add:

aes(stringr::str_wrap(Term, 15), logPvalue)

But in this case the order of the Barplot will be disrupted.

what is the better solution for this situation?

Thanks a lot

R • 76 views
ADD COMMENTlink modified 9 days ago by MatthewP660 • written 9 days ago by Kyle80
4
gravatar for MatthewP
9 days ago by
MatthewP660
China
MatthewP660 wrote:

Hey, try something like

p + scale_x_discrete(labels=scales::wrap_format(30))
ADD COMMENTlink written 9 days ago by MatthewP660
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1744 users visited in the last hour