Open grssnbchr opened 7 years ago
Hi, @grssnbchr
It is a little bit difficult for save GIF with ggplot2 and with a transparent background.
You can try use im.convert()
or gm.convert()
in animation package.
Here is an example.
for (i in 1:10) {
df=data.frame(x=1:10,y=rnorm(10, 1, 2))
ggplot(df, aes(x = x, y = y))+
geom_point()+ theme( legend.background = element_rect(fill = "transparent"), # get rid of legend bg
legend.box.background = element_rect(fill = "transparent"),
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
panel.background = element_rect(fill = "transparent",colour = NA),
plot.background = element_rect(fill = "transparent",colour = NA)
)
ggsave(paste0(tempdir(),"/Rplot",i,".png"),bg="transparent")
}
im.convert(files=file.path(tempdir(),"Rplot*.png"),output = "A.gif",extra.opts = "-dispose previous")
We will improve those functions for a better user experience in few weeks.
Thank you, that basically works, yes. Looking forward to a package update though!
I had the same issue. Use
ggsave(p, filename = "foo.png", bg = "transparent")
This should give you the desired result.
This is a question, not a bug report. I want to generate a GIF with ggplot2 and a transparent background. Even though I set the background to "transparent" in ggplot2's
theme
function, I don't get a transparent background in the final GIF. Is there an option which sets this? Or is this not even possible directly withsaveGIF
?