0

I am kniting an R markdown to produce a report and everything is working perfectly as expected, EXCEPT that in the final chunk I create a series of faceted violin plots (in a loop) and use the chunk options ...

{r facet plots, Tidy=TRUE, echo = FALSE, include=TRUE, warning=FALSE, fig.height = 40, fig.width = 30}

to control the plot size. This works perfectly for the plots but the axis text on the plots becomes minuscule!! As below:

enter image description here

The ggplot call is...

ggplot(FctPlotData, aes(x=TimeGroup, y=OverallTAT)) + 
  geom_violin(trim = FALSE, fill='lightgrey', color="darkblue") +
  xlab("Time of Day (groupings in 4 hour intervals)") +
  ylab("Turnaround Time") + 
  facet_wrap(~(DoW), ncol = 1, scales = "free_y") +
  ggtitle(paste0(spTst, " Turnaround Breakdown by Day of Week and Time of Day")) + 
  theme_pc()

I use a custom theme - theme_pc() - to set a common look and feel to all my plots (with text size specified therein) and it works in all other contexts but not for this?

I have attempted to address this by including

knitr::opts_chunk$set(results = 'asis')

in the top level (setup) chunk but this hasn't helped, does anyone have any insights about how to get the labels to a legible size?

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Peter
  • 118
  • 9

1 Answers1

0

I have found a solution to this ...

Instead of using fig.width and fig.height in the chunk header you can use out.width = "NN%" as shown below

chunk header

Then you get the axis text scaled appropriately with the figure; this scaling doesn't seem to apply to figure heading - but I can live with that :-)

knitted ggplot output

I have also found that you can combine out.width with fig.height to get more control over the proportions of the plots :

enter image description here

Peter
  • 118
  • 9