Save facet_wrap() on multiple pages using ggforce/ggplus

前端 未结 1 1389
滥情空心
滥情空心 2021-01-26 05:21

I got this plot using the code below

library(tidyverse)
ggplot(df2, aes(x =Date, y = Sales, color = id))+ 
  geom_line(size = 0.01, alpha = 0.3)+
  +fac         


        
相关标签:
1条回答
  • 2021-01-26 05:54

    Removing the NAs works well:

    library(ggplus)
    df2 <- df2[!is.na(df2$Sales),]
    pdf("C:\\1\\test.pdf", 7, 5)
    p <- ggplot(df2, aes(x =Date, y = Sales)) +
      geom_line(aes(colour=id),size = 0.01)+
      scale_x_date(breaks = seq(as.Date("2001-01-01"),
                                as.Date("2007-01-01"), by="1 year"),
                   labels = date_format("%Y"))
    facet_multiple(plot = p, facets = 'id', ncol = 2, nrow = 2)
    dev.off()
    

    PS: Another option is using the gridExtra package.

    0 讨论(0)
提交回复
热议问题