I am trying to export a simple plot in .png with transparent background. I am able to export it, but the background stays white.
Mock example
x = c(1, 2, 3)
I've tried this
plot (x)
dev.copy (png,'myplot.png', bg = 'transparent')
dev.off()
And this
plot (x, bg = 'transparent')
dev.copy (png,'myplot.png')
dev.off()
But neither work.
Can someone help?
Save As A Transparent PNG ImageClick “File” -> “Save As”. Select “PNG (*. PNG) as the file format. Note that though a transparent background looks checkered in Photoshop, it will actually be transparent in the final PNG file.
These features make PNG an ideal file type to use for logos, icons, and digital art. Most importantly, PNG is a crowd favorite because it supports transparent backgrounds. Colors (including white) fill all the pixels in a regular image.
If you want to make the graph plot more transparent, then you can make alpha less than 1, such as 0.5 or 0.25. If you want to make the graph plot less transparent, then you can make alpha greater than 1.
x = c(1, 2, 3)
par(bg=NA)
plot (x)
dev.copy(png,'myplot.png')
dev.off()
Instead of saving all parameters, it is better to only save the old value of the parameter that was changed in a call to ´par´ by saving result of ´par´ as in the modified example:
x = c(1, 2, 3)
old.par <- par(bg=NA)
plot (x)
dev.copy(png,'myplot.png')
dev.off()
par(old.par)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With