wilkelab / cowplot

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

ggdraw + draw_grob does not work with ggsave or save_plot ? #170

Open andrewjamesmott opened 4 years ago

andrewjamesmott commented 4 years ago

I am unsure if this is due to my incorrect usage but I cannot save a plot when using ggdraw+draw_grob, is this possible? This does not work with ggsave or save_plot, it produces an error noting an invalid canvas value. As below.

``` r
library(here)
#> here() starts at [removed]
library(tidyverse)
#> Warning: replacing previous import 'vctrs::data_frame' by 'tibble::data_frame'
#> when loading 'dplyr'
library(grid)
library(cowplot)

plot <-  ggplot(mpg, aes(x = hwy, y = cty)) +
          geom_point()

line <-  linesGrob(x = unit(c(0,1), "npc"), y = unit(c(0,1), "npc"))

plot_full <- ggdraw(plot) +
              draw_grob(line)

ggsave("plotfull.png", plot_full, path = here())
#> Saving 7 x 5 in image
#> Error in grDevices::png(..., res = dpi, units = "in"): invalid value of 'canvas'

save_plot("plotfull.png", plot_full)
#> Error in grDevices::png(..., res = dpi, units = "in"): invalid value of 'canvas'

Created on 2020-09-14 by the reprex package (v0.3.0)

clauswilke commented 4 years ago

I cannot reproduce this issue. You'll have to do some more digging. Can you save any plots? Can you save plot? Which combination of package trigger the issue?

andrewjamesmott commented 4 years ago

Yes, saving just 'plot' works fine. Using the export function in Rstudio works with plot_full . I have also attempted with just ggplot2, grid, and cowplot and it does not seem to work.

clauswilke commented 4 years ago

While the presence of the cowplot package seems to trigger this issue, I'm not convinced this is actually a cowplot bug. And also, I can't reproduce the issue. I suggest you ask on stackoverflow, where a larger audience can see this. Maybe somebody else can reproduce this and figure out where things go wrong.