I cannot seem to save a plot when using ggdraw()
+ draw_grob()
. Saving just 'plot1' alone works fine but once I start using ggdraw it no longer works with either ggsave()
or save_plot()
, it produces an error noting an invalid canvas value. Example below:
library(ggplot2)
#> Warning: replacing previous import 'vctrs::data_frame' by 'tibble::data_frame'
#> when loading 'dplyr'
library(cowplot)
library(grid)
plot1 <- 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(plot1) +
draw_grob(line)
ggsave("plotfull.png", plot_full)
#> 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)