Reputation: 1108
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?
Upvotes: 25
Views: 38135
Reputation: 11
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)
Upvotes: 1
Reputation: 1360
x = c(1, 2, 3)
par(bg=NA)
plot (x)
dev.copy(png,'myplot.png')
dev.off()
Upvotes: 36