生成图时抑制 ggpairs 消息

Suppress ggpairs messages when generating plot

ggpairs 在生成绘图时打印出进度条和估计的剩余时间,这在交互式使用时非常好,因为某些计算可能需要几秒钟。但是在制作文档时,比如 R 笔记本,这些打印的消息最终会出现在报告中。 ggpairs had a boolean verbose option, but it's depricated now。有其他选择吗?我好像找不到。

要查看消息,请尝试:

library(GGally) ggpairs(mtcars, columns = c("mpg", "cyl", "hp", "disp", "am", "qsec"))

在文档中它最终包括:

plot: [1,1] [==-------------------------------------------] 4% est: 0s

plot: [1,2] [====-----------------------------------------] 8% est: 6s

plot: [1,3] [=====----------------------------------------] 12% est: 5s

plot: [1,4] [=======--------------------------------------] 16% est: 5s

等等

progress = FALSE 参数将在打印 ggpairs 图时起作用。

ggp = ggpairs(mtcars, columns = c("mpg", "cyl", "hp", "disp"))
print(ggp, progress = F)  # no progress bar
print(ggp)  # progress bar

也可能取决于如何knit。调用进度条的函数为ggmatrix_gtable,默认值为

 progress = interactive() && (pm$ncol * pm$nrow) > 15

因此在非交互式会话中默认不打印进度条。

如果你熟悉dplyr语法,也许下面的管道是最优雅的,不需要保存中间变量

mtcars %>% 
  ggpairs(columns = c("mpg", "cyl", "hp", "disp", "am", "qsec")) %>%
  print(progress = F)

'progress' print 函数中的参数即将弃用。

可以传给ggpairs本身:

library(GGally)
ggpairs(mtcars, 
        columns = c("mpg", "cyl", "hp", "disp", "am", "qsec"),
        progress = FALSE)

没有进展的 ggpairs 的 RStudio 屏幕截图: