rplotpar

How to make multiple plots fill the entire page in Rmarkdown with pdf output


I am trying to have multiple histogram plots rendered from a for loop fill up the entire page on my R Markdown pdf output.

My histogram plots are rendered from the following code

mclogins<-c("sacfreq","logsacfreq","meanvel","logmeanvel", "meanvelx","logmeanvelx", "meanvely","logmeanvely","meanacc","logmeanacc", "meanaccx", "logmeanaccx", "meanaccy","logmeanaccy", "meanamp", "logmeanamp", "meanampx","logmeanampx", "meanampy","logmeanampy")

# dev.off()
par(mar=c(5.1 ,4.1, 4.1 ,2.1),mfrow=c(3,2))

for( i in mclogins){
  hist(df.1log[,i],
       xlab = i,
       main = paste("Histogram of",i),
       col = "lightblue")
}

Where df.1log is the dataset containing values for all variables in mclogins

Right now, my output looks like this: enter image description here

And as you can see, there is much empty space at the bottom of the page.

I have tried the following suggestions:

But it ends up causing the plots to disappear or nothing changes and the blank space is still there.

Thank you so much!


Solution

  • You can set fig.height and fig.width to suite your preferences, but a reasonable starting point could be to add the following to the top of the chunk where you make your visualizations.

    {r, echo = FALSE, fig.height = 28, fig.width = 20}