抑制ggplot中的警告消息

时间:2018-10-16 11:27:10

标签: r ggplot2 gridextra

样本数据:

library(ggplot2)
library(gridExtra)
dat1 <- structure(list(year = c(2012L, 2013L, 2013L, 2014L, 2014L, 2012L, 2013L, 2013L, 2014L, 2014L), 
                       week = c(2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L), 
                       variable = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L), 
                      .Label = c("mod", "obs"), class = "factor"), 
                       value = c(86.54, 82.65, 86.54, 86.16, 86.54, 2, 1.4, 8, 2.1, 11)), 
                       row.names = c(NA, -10L), class = "data.frame")

dat2 <- structure(list(week = c(2L, 1L, 2L, 1L, 2L), 
                       mod = c(86.54, 82.65, 86.54, 86.16, 86.54), 
                       year = c(2012L, 2013L, 2013L, 2014L, 2014L), 
                       obs = c(2, 1.4, 8, 2.1, 11)), class = "data.frame", row.names = c(NA, -5L))


p1 <- ggplot(dat1, aes(x = week, y = value, colour = variable)) + geom_line() + geom_point() + facet_wrap(~ year) 
p2 <- ggplot(dat2, aes(x = obs, y = mod)) + geom_point(aes(size = 1)) + geom_abline(intercept = 0, slope = 1) 

grid.arrange(p1, p2, nrow = 2)

geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?

如何抑制警告消息,以便grid.arrange在打印之前必须等待一段时间?

编辑

此图是一个循环,因此有时我会有多个组,因此在这些情况下,它不会生成任何警告。

这与之前关于SO的类似问题不同,因为在这里,我只需要在生成单个组的情况下才禁止显示警告

0 个答案:

没有答案