[R] Still struggling with facet_grid_paginate() from package ggforce.
Rui Barradas
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sun Dec 1 22:45:53 CET 2019
Hello,
Here are two ways.
The first is an adaptation from your code. It uses facet_wrap_paginate,
not *_grid_*.
plotObj2 <- vector("list",2)
for(pg in 1:2) {
plotObj2[[pg]] <- ggplot(egDat) +
geom_point(aes(y = obsd, x = x),
na.rm = TRUE, shape = 20, colour = "blue") +
geom_line(aes(y = fit2, x = cPred)) +
facet_wrap_paginate(facets = ~Trt,
ncol = 4, nrow = 3, page = pg) +
theme_bw()
}
print(plotObj2)
The second is an adaptation of SO[1]. It needs two calls to the plot
code and it's slower but gets the job done.
g <- ggplot(egDat) +
geom_point(aes(y = obsd, x = x),
na.rm = TRUE, shape = 20, colour = "blue") +
geom_line(aes(y = fit2, x = cPred)) +
facet_wrap_paginate(facets = ~Trt, ncol = 4, nrow = 3, page = 1) +
theme_bw()
n <- n_pages(g)
for(i in 1:n){
print(g + facet_wrap_paginate(~Trt, ncol = 4, nrow = 3, page = i))
}
print(g)
Hope this helps,
Rui Barradas
[1] https://stackoverflow.com/a/58373858/8245406
Às 11:46 de 01/12/19, Rolf Turner escreveu:
>
> I am trying to produce a ggplot2 graphic in which there is a single
> conditioning variable with a large number of levels (24).
>
> If I use facet_grid() I get a plot with either 24 rows or 24 columns,
> both of which look like hell.
>
> I thought that facet_grid_paginate() would rescue me, but it doesn't
> seem to. I ask for 3 rows and 4 columns, and thought that I would get
> two 3 x 4 pages Instead I get six pages with only one row (of four
> facets) per page.
>
> Am I misunderstanding something? Doing something silly? Or is this a bug?
>
> I have attached a reproducible example, along with the data set on which
> it depends.
>
> Grateful for any insight.
>
> cheers,
>
> Rolf Turner
>
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list