代码之家  ›  专栏  ›  技术社区  ›  89_Simple

在ggplot中禁止显示警告消息

  •  0
  • 89_Simple  · 技术社区  · 6 年前

    样本数据:

    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 打印前需要等待一段时间吗?

    编辑

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

    这与之前类似的问题不同,因为这里我只需要在生成单个组时禁止警告

    0 回复  |  直到 6 年前