1

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!

Shivvy
  • 67
  • 2
  • 6

1 Answers1

4

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}

rjen
  • 1,938
  • 1
  • 7
  • 19
  • Thank you so much it worked! I tried the same with plots generated with by `ggplot`, and arranged by `ggarrange`. The font size of the graphs are extremely small when I employ this. Do you know of a way to change it? – Shivvy Nov 07 '20 at 00:37
  • @Shivvy: My pleasure. If you are using ggplot2, you can have a look at https://stackoverflow.com/questions/14942681/change-size-of-axes-title-and-labels-in-ggplot2 – rjen Nov 07 '20 at 14:58