0

I started working in Rmd as I prefer it's output after chunks to the console of an R script.

par(mfrow = c(x, y)) however is not working for inline output. So an R chunk with

par(mfrow = c(x, y)) boxplot() boxplot()

etc. does not show multiple plots. boxplot() is base R.

Is there a resource explaining why?

its.me.adam
  • 333
  • 2
  • 11

1 Answers1

2

The x and y in par(mfrow = c(x, y)) designate the rows and columns, not the plots. You want something like:

set.seed(123)
mat <- matrix(sample(120:200,200,TRUE), ncol=10, nrow=20)
par(mfrow=c(1,2))
boxplot(x = list(mat[,1], y = mat[,2]))
boxplot(x = list(mat[,3], y = mat[,4]))

par(mfrow=c(1,1))
``
user12728748
  • 8,106
  • 2
  • 9
  • 14
  • Sorry, I made a mistake in my question. See above for the issue. – its.me.adam Feb 10 '20 at 18:47
  • If you defined your own boxplot function that does not use `base` graphics, then you might have to use something like `cowplot::plot_grid` (for `ggplot2` objects) or viewports for `grid` graphics. – user12728748 Feb 10 '20 at 19:18
  • See also https://stackoverflow.com/questions/37115276/control-alignment-of-two-side-by-side-plots-in-knitr for chunk options that may help. – user12728748 Feb 10 '20 at 19:26
  • `boxplot()` is base R. Also I am not knitting so chunk options shouldn't make a difference AFAIK. – its.me.adam Feb 10 '20 at 20:01