从Cowplot包中找到ggsave和save_plot似乎不适用于ggdraw + draw_grob吗?

问题描述

使用ggdraw() + draw_grob()时似乎无法保存绘图。仅保存'plot1'可以很好地工作,但是一旦我开始使用ggdraw,它将不再与ggsave()save_plot()一起使用,它会产生一个错误,指出无效的canvas值。下面的示例:

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,"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(...,units = "in"): invalid value of 'canvas'

reprex package(v0.3.0)于2020-09-14创建

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)