Question: Barplot labeling squeezed the bars
0
gravatar for Kai_Qi
8 months ago by
Kai_Qi100
Chicago, IL
Kai_Qi100 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 • 299 views
ADD COMMENTlink modified 8 months ago by MatthewP880 • written 8 months ago by Kai_Qi100
4
gravatar for MatthewP
8 months ago by
MatthewP880
China
MatthewP880 wrote:

Hey, try something like

p + scale_x_discrete(labels=scales::wrap_format(30))
ADD COMMENTlink written 8 months ago by MatthewP880
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: 1691 users visited in the last hour
_