Export a plot to .png with a transparent background

I am trying to export a simple plot to .png with a transparent background. I can export it, but the background remains white.

Layout Example

x = c(1, 2, 3)

I tried this

plot (x)

dev.copy (png,'myplot.png', bg = 'transparent')
dev.off()

And this one

plot (x, bg = 'transparent')

dev.copy (png,'myplot.png')
dev.off()

But no one is working.

Can anyone help?

+6
source share
1 answer
x = c(1, 2, 3)
par(bg=NA)
plot (x)

dev.copy(png,'myplot.png')
dev.off()
+9
source

Source: https://habr.com/ru/post/1016768/


All Articles