2

My specific issue is evident when I output 3 plots to a html report using grid.arrange, sometimes the last plot (which is a tableGrob) is cropped.

I am using 3 separate grid.arrange() statements to place a boxplot, a time series plot and a tableGrob in a html report using knitr.

Code being used to output is:

  grid.arrange(p1,top=main)
  grid.arrange(p2TS)

  if(nrow(over5)>0){
    tg=tableGrob(over5,theme=tt3,rows = NULL)
    tg$widths = unit(rep(1/4, ncol(tg)), "npc")
    grid.arrange(tg)

  }

This displays perfectly when the tg object has less than roughly 10 rows of data.

However in testing larger datasets I found that the grid.arrange(tg) outputs in a fixed height "window" in the report which is not desirable.

My question is how can I change the height of the grid.arrange(tg) ouput to match the height of the tg object contained inside (with some top and bottom margin)??

I would appreciate understanding the mechanism by which these properties are changed so I can fine tune my output. I would have a 3x1 grid display all 3 outputs in one line of code if possible but all plots get condensed and unreadable so that is why I have 3 separate grid.arrange() statements. I Guess my real issue is I don't understand how there properties are manipulated here.

Help is greatly appreciated.

Martin O Leary
  • 633
  • 2
  • 10
  • 29
  • Please provide [a reproducible example](http://stackoverflow.com/a/5963610/1412059) including your knitr code. – Roland Jan 22 '16 at 13:20
  • Hi Roland, apologies for poor quality of question, I have since found a workaround to use `print(knitr::kable(tg))` instead on `grid.arrange(tg)` and it works fine for now – Martin O Leary Jan 22 '16 at 13:25
  • You are encouraged to answer your own question if you found a solution. – Roland Jan 22 '16 at 13:28

1 Answers1

1

I found a workaround to use kable which prints a HTML table to the report instead of grid.arrange() with tableGrob() :

  grid.arrange(p1,top=main)
  grid.arrange(p2TS)

  if(nrow(tg)>0){
    print(knitr::kable(tg))
  }

Also as I was running this code within a for loop I needed to use a workaround on this issue page which requires me to wrap the kable in a print() statement.

Martin O Leary
  • 633
  • 2
  • 10
  • 29