ggplot2如何跨2页面分别绘制单个图形

时间:2018-06-07 15:48:39

标签: r ggplot2 gplots

我有这段代码

g=ggplot(a, aes(x = TIME, y = DV,group = ID))
g + geom_point(data = a,  colour="red", size=2) +
    theme_bw() +
    geom_smooth(method = 'loess', se = FALSE,colour="black") +
    facet_wrap( ~ ID, ncol = 4,nrow = 6, scales = 'free')

我在一页上得到一张6 * 4 = 24个方面的情节。如何将其拆分为2页,每页有12个单独的图?

1 个答案:

答案 0 :(得分:0)

例如:

library(tidyverse); library(ggforce)

p <- mtcars %>%
  rownames_to_column("model") %>%
  ggplot(aes(wt, mpg, label = model)) +
  geom_text(size = 2) +
  coord_cartesian(clip = "off")

p + facet_wrap_paginate(~model, nrow = 4, ncol = 4, page = 1)
p + facet_wrap_paginate(~model, nrow = 4, ncol = 4, page = 2)