title: How do I represent an enormous bar plot with very long axis labels in R and ggplot?
body: <p>I have a ggplot of bar graphs for each cluster.</p>
  <p>The axis labels (&quot;Path&quot;) for the bar plot are all unique and long, but they are grouped by &quot;PathTypes&quot; and &quot;Cluster&quot; - info which I want to represent on the bar graphs. I use a texture (stripes, dots, etc) from the ggpattern package to represent the &quot;PathType&quot; and I use colors to represent the &quot;Cluster&quot;.</p>
  <p>The resulting graph I produce is illegible bc it's just too large. I've been butting heads with facet_grid and facet_wrap. I am fine with using 2-3 pages to represent all the clusters, but I'm unsure about how to split the data smartly to accomplish that.</p>
  <p>Example code follows:</p>
  <pre><code>library(data.table)
  library(ggpattern)
  library(gridExtra)
  library(ggpubr)
  library(truncnorm)
  library(ggplot2)
  library(stringi)
  
  # generating sample data for data table called all.cluster.dt 
  
  PathType &lt;- sample(x = c(&quot;Type1&quot;, &quot;Type2&quot;, &quot;Type3&quot;, &quot;Type4&quot;, &quot;Type5&quot;),   # create the PathType column
                     size = 400,
                     replace = T)
  Score &lt;- rtruncnorm(n = 400, a = 15, b = 90, mean = 55, sd = 15)     # create the Score Column
  
  Path &lt;- NA     # initialize the Path column
  Path.generator &lt;- function() {     # function to write unique Paths
    a &lt;- do.call(paste0, replicate(10, sample(LETTERS, 15, TRUE), FALSE))
    single.Name &lt;- paste(a, collapse = ' ')
    return(single.Name)
  }
  
  cluster &lt;- sample(x = c(1:14),    # create the Cluster column
                    size = 400,
                    replace = T)
  
  all.cluster.dt &lt;- data.table(     # create the data table with desired columns 
    PathType,
    Score,
    Path,
    cluster
  )
  
  for(i in 1:length(all.cluster.dt$Path)){     # loop down Path column calling function to generate unique Path name for each row
    all.cluster.dt$Path[i] &lt;- Path.generator()
  }
  
  wrap.it &lt;- function(x, len)     # function to try and wrap long Path label text 
  { 
    sapply(x, function(y) paste(strwrap(y, len), 
                                collapse = &quot;\n&quot;), 
           USE.NAMES = FALSE)
  }
  
  # Call this function with a list or  vector
  wrap.labels &lt;- function(x, len)
  {
    if (is.list(x))
    {
      lapply(x, wrap.it, len)
    } else {
      wrap.it(x, len)
    }
  }
  
  wr.lap &lt;- wrap.labels(all.cluster.dt$Path, 40)     # wrap Path labels to 40 characters long
  all.cluster.dt$Path &lt;- wr.lap
  
  all.cluster.dt$Path &lt;- factor(all.cluster.dt$Path,     # group and factorize the data by PathType and Score
                            levels = unique(all.cluster.dt$Path[order(all.cluster.dt$PathType, all.cluster.dt$Score)]))
  
  cluster.color.df &lt;- data.frame(&quot;cluster&quot; = c(1:14),     # add custom colors to represent which Cluster the Path belongs to
                                 &quot;color&quot; = c(&quot;#F5F2D4&quot;, &quot;#CAD8F2&quot;, &quot;#8FB6FF&quot;, &quot;#FFFDD7&quot;, &quot;#DADADA&quot;, &quot;#DAEB9B&quot;, &quot;#EED1F2&quot;, &quot;#C9E2D0&quot;, &quot;#FFDFA2&quot;, &quot;#DFFFD6&quot;, &quot;#F6DFDE&quot;, &quot;#E2DEF5&quot;, &quot;#F0B8BC&quot;, &quot;#CAF3EF&quot;))
  setDT(all.cluster.dt)[cluster.color.df, color := i.color, on = .(cluster)]     # match color to cluster in all.cluster.dt
  
  bar.plots &lt;- ggplot(all.cluster.dt, aes(x=Score, y=Path)) +
    ggpattern::geom_col_pattern(     # adds texture/patterns to the bars based on the PathType column
      aes(pattern = `PathType`),
      fill = all.cluster.dt$color,
      colour = &quot;black&quot;,
      pattern_density = 0.2,     # how dense the pattern should be
      pattern_fill = &quot;black&quot;,
      pattern_spacing = 0.1) +
    scale_x_continuous(expand = c(0, 0), limits = c(0, 90)) +
    theme_bw() +
    theme(axis.title.y = element_blank()) +
    theme(legend.position = &quot;none&quot;,
          text = element_text(size = 8)) 
  
  bar.plots + facet_grid(rows = vars(cluster), scales = &quot;fixed&quot;)     # draw the bar graph
  </code></pre>
  <p>I now attempt to use grid.arrange and ggsave to arrange the plots by Cluster on a page, but get an error: &quot;replacement has 17 rows, data has 400&quot;...</p>
  <pre><code>pdf(&quot;bar_graphs.pdf&quot;, wi=8.1,hei=10.6)
  
  do.call(grid.arrange, bar.plots)
  ggsave(&quot;bar_graphs.pdf&quot;, marrangeGrob(bar.plots, nrow=4, ncol=2))
  
  dev.off()
  </code></pre>
  <p>Any answers that provide the overall solution to my goal (getting my bar graphs into a legible figure) or elucidate why I get an error arranging grobs is much appreciated.</p>