1

I am trying to plot very long and thin barplots and am satisfied with layout(), where I have been using matrix(1:200, 200, 1) to define my plotting area. See example of such a plot in the attached image.

example plot

I'd like to be able to do this where I have more than 200 datasets to plot.

Error in layout(mat = matrix(1:201, 201, 1)) : too many rows in layout, limit 200

Any help would be appreciated.

Jamie
  • 11
  • 2
  • 1
    Looks like that limit is in C code, which makes it pretty hard to modify (i.e., want to re-compile R from source, with no guarantee that it will work). It may be possible to generate the plot without using `layout`... here's a *somewhat* similar example putting [vertical histograms on single plot](https://stackoverflow.com/a/13334294/903061) – Gregor Thomas Mar 23 '20 at 18:08
  • Another option would be something like `Hmisc::subplot`. One big plot, and then each barplot is a subplot. – Gregor Thomas Mar 23 '20 at 19:31

1 Answers1

0

I have found that par(mfrow = c(300, 1)) does exactly what layout(mat = matrix(1:300, 300, 1)) does, but without the limit warning. However, when I push the limit further I get a warning:

Error in plot.new() : figure margins too large

Are there ways around this? Particularly for exporting plots to files, plotting within rstudio is less important to me. Thanks again.

Jamie
  • 11
  • 2
  • I can post a way to do a horizontal bar chart with ggplot2, but for the example data you're showing (single value), all plots start at the y-axis, unlike your example. – markhogue Mar 23 '20 at 18:35
  • Are you running the code within a file plot device that is suitably large? e.g., `png("testplot.png", height = 9000, width = 1000); par(mfrow = c(300, 1))`? – Gregor Thomas Mar 23 '20 at 18:49
  • I just picked a big number for the height - you should think about how many pixels you need per barplot and how many are taken up by the axis and labels. And I'm assuming you're also using `par` to adjust the margins to basically nothing for all the small figures. – Gregor Thomas Mar 23 '20 at 19:29