Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot2: Save directly to harddrive

Tags:

r

ggplot2

I know that the combination of ggplot() and then ggsave() will create and save the plots to the hard drive.

Is there any chance of directly saving the graph to the hard drive without showing/displaying it first?

like image 881
FooBar Avatar asked Oct 30 '25 04:10

FooBar


1 Answers

You have to save the ggplot into a variable, then define plot in ggsave, like so:

testplot <- ggplot(mtcars, aes(cyl, qsec)) + geom_point()
ggsave('test.png', plot = testplot)
like image 78
Nick DiQuattro Avatar answered Oct 31 '25 19:10

Nick DiQuattro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!