0

I have created a boxplot in R using ggplot, changing the background of the plot and panel, with the plan that I can export it and then use it in a document where it will match the background of the document, thus essentially looking transparent. This almost works, but I'm stymied by a thin white line that appears around the entire image when it's exported and then copied into the document.

I've tried removing the margins with the following code, but this doesn't remove the line - it only removes the margins around the plot (as you might imagine). Other answers I have found are variations on this theme.

boxplot +
  theme(plot.margin = grid::unit(c(0, 0, 0, 0), "mm"))

Any help? I've included an image to make it clear what I'm talking about...

![Example of white line issue](https://imgur.com/a/4FvpM)

Jaccar
  • 1,720
  • 17
  • 46
  • perhaps `theme(plot.background = element_blank())` – Nate Mar 11 '18 at 15:32
  • or maybe `theme(plot.background = element_rect(color = NA))` – Jack Brookes Mar 11 '18 at 15:33
  • Thanks for your responses! Unfortunately those both give me a white background when I copy or export the resulting image, rather than a transparent one, or one that matches the colour I am going for but excludes the white outline. – Jaccar Mar 11 '18 at 16:56
  • 5
    Please include a minimal working example with your question so that others can replicate the problem: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Michael Harper Mar 11 '18 at 17:15
  • For example, replace `boxplot` with `ggplot(mpg, aes(class, hwy)) + geom_boxplot()` and then add any other changes. Also, how are you saying the image exactly? – Michael Harper Mar 11 '18 at 17:19
  • Look at the second answer of the duplicate. Making a proper transparent plot is the way to go here, I think! – Axeman Mar 12 '18 at 09:16

0 Answers0