0

I have this code

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')

I get a plot with 6*4 = 24 facets on one page. How can I split it in 2 pages, with 12 individual plots in each page?

Jon Spring
  • 55,165
  • 4
  • 35
  • 53
  • The [`ggforce`](https://cran.r-project.org/web/packages/ggforce/index.html) package has a function called `facet_wrap_paginate` that is designed for this exact purpose. – Dan Jun 07 '18 at 15:53
  • 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')+facet_wrap_paginate(~ID, nrow = 3, ncol = 4, page=1) it only shows one page containing 12 individual figures the second page is invisible. Kinldy guide me – Muhammad Faisal Jun 07 '18 at 16:22
  • 1
    You need to provide a reproducible example. That means, supplying your data (e.g., using `dput`) as well as your code. But one clear problem is that you're using `facet_wrap` and `facet_wrap_paginate` at the same time and your page number is a single number. Have a quick look at the example in the documentation... – Dan Jun 07 '18 at 16:28
  • data set is too large to put here. I am not sure what to put in facet. My data consists of time concentration of 24 IDs. so facet_wrap_paginate(~ID, nrow = 3, ncol = 4, page=1) should be correct? – Muhammad Faisal Jun 07 '18 at 16:54
  • data has time column concentration column and ID column – Muhammad Faisal Jun 07 '18 at 16:55
  • If you look at the example in the documentation, you'll see it's done inside a loop where `page` is a variable. You can use a dummy data set to provide a [MCVE](https://stackoverflow.com/help/mcve). – Dan Jun 07 '18 at 17:02

1 Answers1

0

As an example:

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) 
Jon Spring
  • 55,165
  • 4
  • 35
  • 53