Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andrewjamesmott opened this issue Sep 14, 2020 · 3 comments
Open

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

andrewjamesmott opened this issue Sep 14, 2020 · 3 comments

Comments

@andrewjamesmott
Copy link

andrewjamesmott commented Sep 14, 2020


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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants