#this question is more about a syntax choice than a technical issue, so this code chunk is more of a formality library(ggplot2) mt_plot <- ggplot() + geom_point(data = mtcars, aes(x=mpg, y = disp)) ggsave("mt_plot.png", mt_plot, dpi = 300, height = 4, width = 6)
ggsave() has as its first argument the filename to be saved to, rather than the gg object itself. This seems different than other canonical "export"-type functions, like write_csv() and everything like it, where the object to be exported is always the first argument in the export function to match the "pipeable" grammar of the tidyverse. In the example chunk above, I can't just stack the call to ggsave at the end of a pipeline, I have to start a new "sentence" specifically to save the plot.
Why is the export syntax different for ggsave(), such that piping into ggsave() doesn't work? Is it to be closer to base R's plot export functions (png/pdf/etc)? Does it have something to do with the "+" symbol that makes piping not work the same way? Does it have to do with a grammar choice to separate creating a plot and exporting that plot?