0

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?

enter image description here

francoiskroll
  • 1,026
  • 3
  • 13
  • 24
  • Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Oct 26 '19 at 15:45
  • Why did you set size in the bars? Seems like the overlap is just the thick outline you've put on the bars. Either way, without data, I'm just guessing – camille Oct 26 '19 at 18:13
  • I did not add data because I think it is specifically a plot/export issue, but fair enough, sorry about that. I edited my question. – francoiskroll Oct 28 '19 at 17:46

0 Answers0