Here is some data:
df <- structure(list(condition = c("injected", "uninjected", "injected",
"uninjected"), variable = c("var1", "var1", "var2", "var2"),
value = c(90, 0, 0, 0)), row.names = c(2L, 4L, 6L, 8L), class = "data.frame")
My ggplot code looks like:
ploteg <- ggplot (data = df, aes (x = condition, y = value, fill = variable, colour = variable)) +
geom_bar (stat = 'identity', width=0.6, position=position_dodge(width=0.7), size=1.1)
My export command is:
ggsave('test.eps', plot=ploteg, width=65, height=90, unit='mm', bg='transparent')
or
ggsave('test.png', plot=ploteg, width=65, height=90, unit='mm', bg='transparent')
I added the png below. Now compare the spacing between bars in uninjected vs injected. What I want is the spacing to be consistent. I don't think it should change whether the value is 0 (so no fill/only outline) or anything different than 0 (fill + outline). This issue does not seem to happen within R (I'll let you try with the data above), only once the plot is exported, which is why I believe it might be an actual export glitch.
And 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.
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?