Tables and Figures side-by-side in Knitr or RMarkdown Beamer

后端 未结 4 2093
北海茫月
北海茫月 2020-12-31 12:58

I am trying to create a Beamer Presentation slide in RMarkdown / Knitr . In the slide I would like to have a table and a figure placed Side-by-side , and then some more text

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 13:30

    Consider using a two column layout, like you would have to do if you were doing this directly in Beamer. See for example:

    • this question on doing this with the tools available with RStudio. (Please note that this is one area where RStudio and the RMarkdown package have evolved a lot recently and the question is somewhat dated, but it does hint at the features now available.)
    • this question for a solution with inline LaTeX and Pandoc. (This will also work with RStudio as the newer releases use a bundled copy of pandoc as the Markdown engine.)
    • this post on the pandoc mailing list discussing how to include Markdown inside of your LaTeX blocks, e.g. the Beamer commands/environments for columns.
    • this question on TeX Stack Exchange could help you, but you would need to adapt it a bit for RMarkdown (the question uses the Sweave-style syntax for embedding R into LaTeX with knitr).

    The basic idea for your problem would be a two-column layout for the upper portion of the slide, and a one-column layout for the bottom. You then put the individual R code blocks into their own column. (You may need to play with vertical spacing if the two figures differ in size.)

    The Rpres format is all-or-nothing on column layouts for a given slide (at least last time I checked), so that solution would be less than ideal when you want the bottom part of the slide to be a single 'column'.

    Another solution would be combining the two figures into one and then displaying the merged figure. I'm not sure how you would do with a table and a graphic, but for two graphics, you could use the gridExtra package to place two lattice or ggplot2 (or even an unholy mixture of both) next to each other in a single grid and thus in a single, combined figure.

提交回复
热议问题