Centre a plot to the middle of a page using Knitr

后端 未结 1 1389
说谎
说谎 2021-02-19 08:05

I\'d like to align a plot to the center of a page of a knitr-generated pdf document. I can horizontally align the plot to the center using fig.align=\'center\' but

相关标签:
1条回答
  • 2021-02-19 08:47

    On the LaTeX side, a vertically centered figure must be a figure with position p. How this can be achieved using knitr depends:

    • If the figure has a caption, it is placed in a figure environment (see fig.env). Then only the additional option fig.pos = 'p' is needed.
    • If the figure has no caption (which is usually bad), you can manually add the figure environment:

      \begin{figure}[p]
      
      ```{r,fig.align='center',out.extra='angle=90', echo=FALSE}
      
      library(ggplot2)
      ggplot(diamonds, aes(y=carat, x=price, colour=clarity))+geom_point()+
      facet_wrap(~cut)
      
      ```
      \end{figure}
      

    Note that this works when compiling to PDF but restricts you to PDF as output format.

    0 讨论(0)
提交回复
热议问题