Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

R ggplot barplot: spacing between dodged bars is not consistent

$
0
0

My ggplot code looks like:

ggplot (data = mosa, aes (x = condition, y = perc, fill = pheno, colour = pheno)) +
      geom_bar (stat = 'identity', width=0.6, position=position_dodge(width=0.7), size=1.1)

For the context, I am adding an outline to my bars (with colour= and size=) so we can see a "flat" bar when the value is 0. Very annoyingly, this seems to create inconsistency in spacings between dodged bars when exporting; example below. Compare the spacing between dodged bars in uninjected, and spacing between dodged bars in both. Essentially, it seems like the width of a bar with outline only (so when the value is 0) is thinner than the width of a bar with an outline + a fill.

My export command:

ggsave('slc24a5xtbx5a_a4.png', plot=stacka4, width=55, height=72, unit='mm', bg='transparent')

Can someone help?

enter image description here

Edit: I have (kind of) solved my problem by replacing 0 values with a very low value (eg. 0.3), and removed any outline. This gives a similar effect of "flat" bar, without the widths issues. Far from elegant though. Am I missing something?


Viewing all articles
Browse latest Browse all 201867

Trending Articles