ggplot2: Save directly to harddrive

ggplot2, r

Solution

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)

Problem

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?

Original source