Tables and figures side by side in Knitr or RMarkdown Beamer

I am trying to create a Beamer presentation slide in RMarkdown / Knitr. On the slide, I would like to have a table and a shape, located side by side, and then another text below. I can only get to my attempt, as shown in the code. I would like to have a density graph located next to the Hmisc table.

I do not use Kable or xtable, since I get more control over tables with Hmisc.

Also, how to adjust the text characteristics (font size, type, color) in individual slides?

--- title: "BeamerTest1" subtitle: Beamer Subtitle author: "Author" output: beamer_presentation: theme: CambridgeUS colortheme: "beaver" fonttheme: "structurebold" --- ## Slide with Table, Figure and Text My topic for this slide \scalebox{0.35}{ ```{r hmisc-table, echo=FALSE, message=FALSE, results='asis'} library(Hmisc) latex(head(mtcars), file='', table.env=FALSE, center='none') ``` } ```{r, echo=FALSE, fig.show='hold', fig.height=1, fig.width=2.5} library(ggplot2) mt <- ggplot(mtcars, aes(mpg)) + geom_density(alpha=.2, fill="#FF6666") + theme(axis.title.x = element_text(size=10),axis.text.x = element_text(size=8), axis.title.y = element_text(size=10),axis.text.y = element_text(size=8)) mt ``` - Here is some Bullet Text - And some more - Subtext - More Subtext 

thanks

+6
source share
3 answers

I think you want to set the chunk fig.align=right option as described here

+1
source

Think about how to use a two-column layout, how you would need to do this if you would do it directly in Beamer. See for example:

  • this question is to do this with the tools available with RStudio. (Note that this is one of the areas where RStudio and the RMarkdown package were recently developed, and the question is somewhat outdated, but it hints at the available features.)
  • this question is for a solution with built-in LaTeX and Pandoc. (This will also work with RStudio, as new releases use the included copy of pandoc as a Markdown mechanism.)
  • this is a post on the pandoc mailing list that discusses how to enable Markdown inside your LaTeX blocks, for example. Beamer commands / environments for columns.
  • this question on TeX Stack Exchange might help you, but you need to adapt it a bit for RMarkdown (the question uses Sweave style syntax to embed R in LaTeX with knitr).

The main idea for your problem would be a two-column layout for the top of the slide and a single-line layout for the bottom. Then you put the individual blocks of R code in your own column. (You may need to play at vertical intervals if the two numbers are different in size.)

The Rpres format is “all or nothing” in the column layouts for this slide (at least the last time I checked), so the solution would be less ideal if you want the bottom of the slide to be single, column " .

Another solution would be to combine the two shapes into one, and then display the merged shape. I'm not sure how you will do with the table and graphics, but for two graphs you can use the gridExtra package to place two lattice or ggplot2 (or even an unholy mixture of both) next to each other in one grid and, therefore, in one combined form .

+1
source

issue with two column layouts in the ray view. But in the same post there is a workaround:

In short: the error is related to the pandoc conversion mechanism, which treats everything between \begin{...} and \end{...} as TeX . This can be avoided by specifying a new definition for begin{column} and end{column} in the yaml header.

Create mystyle.tex and write there:

 \def\begincols{\begin{columns}} \def\begincol{\begin{column}} \def\endcol{\end{column}} \def\endcols{\end{columns}} 

In the Rmd file, use these new definitions

 --- output: beamer_presentation: includes: in_header: mystyle.tex --- Two Column Layout ------- \begincols \begincol{.48\textwidth} This slide has two columns. \endcol \begincol{.48\textwidth} ```{r} #No error here i can run any r code plot(cars) ``` \endcol \endcols 

And you will get:

enter image description here

0
source

Source: https://habr.com/ru/post/981147/


All Articles