I have a bunch of plots which I need to save in a given filename structure.
export_png <- function(p, fn, h, w){
ggsave(filename = paste(fn, "-", date, ".png", sep = ""), plot = p,
height = h,
width = w
)}
However, this requires that I define height and width for all plots at their call of this function. Since I am plotting time series with monthly incoming data, I would like to automatically set h
& w
.
For some with plots large legends, I stretch the plot via helper parameters dynamically...
export_png(p = large_plot, fn = "large",
h = helper1,
w = helper2)
...but some others don't really need them, because the legends are small and ggplot2's default dimension calculation is fine.
export_png(p = normal_plot, fn = "normal", h = N, w = M)
Is there some way to pass these plots' default dimensions into my function, so I don't have to determine N
& M
manually?
I've looked at two similar questions, but they utilise defined dimensions at some point.