Split facet diagram into parcel list

Huge facet fan in ggplot2 . However, sometimes I have too many subplots, and it would be nice to split them into a list of plots. for example

 df <- data.frame(x=seq(1,24,1), y=seq(1,24,1), z=rep(seq(1,12),each=2)) df xyz 1 1 1 1 2 2 2 1 3 3 3 2 4 4 4 2 5 5 5 3 . . . . . . . . myplot <- ggplot(df,aes(x=x, y=y))+geom_point()+facet_wrap(~z) myplot 

enter image description here

How can I write a function to get the received graph and break it into a list of graphs? Something in this direction

 splitFacet <- function(subsPerPlot){ # Method to break a single facet plot into a list of facet plots, each with at most `subsPerPlot` subplots # code... return(listOfPlots) } 
+8
r ggplot2
source share
1 answer

While I was looking for a solution for this, I can traverse ggplus. In particular, the facet_multiple function:

https://github.com/guiastrennec/ggplus

Allows you to divide the facet into several pages, indicating the number of graphs that you want on the page. In your example, this would be:

 library(ggplus) df <- data.frame(x=seq(1,24,1), y=seq(1,24,1), z=rep(seq(1,12),each=2)) myplot <- ggplot(df,aes(x=x, y=y))+geom_point() facet_multiple(plot = myplot, facets = 'z', ncol = 2, nrow = 2) 

That's what you need? It worked for me.

+3
source share

All Articles