wilkelab / cowplot

cowplot: Streamlined Plot Theme and Plot Annotations for ggplot2
https://wilkelab.org/cowplot/
704 stars 84 forks source link

save_plot with dimensions not working #90

Closed fungs closed 6 years ago

fungs commented 6 years ago

In cowplot 0.9.2 and earlier, if I use the save_plot function and pass it a width and hight argument, it does not work due to ambiguity.

save_plot("out.pdf", p, width=297, height=210, units="mm")

Error message:

Error in cowplot::ggsave(filename = filename, plot = plot, width = base_width *  : 
  formal argument "width" matched by multiple actual arguments
Calls: save_plot
Execution halted

Instead, calling ggsave works.

clauswilke commented 6 years ago

I finally had a chance to look at this. That it worked in the past was an accident, because you're misusing the save_plot() API. You should specify base_width and base_height instead of width and height, and then it works as expected:

save_plot("out.pdf", p, base_width=297, base_height=210, units="mm")

Also, the benefit of save_plot() is the width and height calculations if you're making larger plot grids. If you're simply specifying width and height in absolute values then there's no benefit to using save_plot() over ggsave().

Leaving this issue open for now because I want to ponder a bit longer whether this should be fixed. In any case, things currently work as expected.

fungs commented 6 years ago

Thanks, I will try this next time I use cowplot. I don't remember exactly why I used save_plot over ggsave, but there was a specific reason.

clauswilke commented 6 years ago

Usage of width or height now creates a meaningful error.

fungs commented 6 years ago

Great!