Rmarkdown 中的并排 Xtables [英] Side by side Xtables in Rmarkdown

查看:15
本文介绍了Rmarkdown 中的并排 Xtables的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了在 RMarkdown-HTML 中并排创建 xtables 的答案knitr、R Markdown 和 xtable:HTML 中的 xtable 表格表

I have seen answers to creating side by side xtables in RMarkdown-HTML knitr, R Markdown, and xtable: xtable tables within HTML table

以及如何在 Sweave 中直接创建并排的 xtablesR:用xtable()打印两张表

and how to create side by side xtables in Sweave directly R: Print two tables with xtable ()

但是 Rmarkdown/Pandoc 中的并排 xtables 怎么样?

But how about side by side xtables in Rmarkdown/Pandoc?

在我的 *Rmd 文件中

In my *Rmd file I have

```{r , results='asis', message=FALSE, echo=FALSE}
female.bmi <- lm(bmi ~ AGEGROUP + RACE + GEO_SPA + FPL_FIN + as.factor(year),
              data=lach[lach$GENDER=='Female',] )
xtable(female.bmi, comment=FALSE, caption = 'Linear regression of BMI for females')
male.bmi <- lm(bmi ~ AGEGROUP + RACE + GEO_SPA + FPL_FIN + as.factor(year),
            data=lach[lach$GENDER=='Male',] )
xtable(male.bmi, comment=FALSE, caption = 'Linear regression of BMI for males')
```

然后我编译如下:

knit('Modeling/simple.rmd', 'Modeling/simple.md') # creates md file
pandoc('Modeling/simple.md', format='latex') # LaTeX/PDF

这些显示为单独的表格 - 很好!但是我怎样才能让它们并排显示子图/子表?我试图在 {r}print(xtable) 代码周围集成 Latex 子图代码,但无济于事.

These show up as separate tables - good! But how can I get them to display as side by side subfigures/subtables? I've tried to integrate Latex subfigure code around the {r}print(xtable) code to no avail.

推荐答案

好的,使用 R markdown 很容易生成它.以下是我的代码和结果:

Ok it is very easy to produce it using R markdown. Below is my code and result:

我结合了您链接到的示例:

I combined the example you linked to:

这是.Rmd文件的代码:

---
title: " 2 tables in markdown side by side"
author: "Marcin Kosiński"
date: "2014"
output: 
   pdf_document:
      includes:
         in_header: header2.tex
      highlight: pygments
      toc: true
      toc_depth: 3
      number_sections: true
---

```{r,echo=FALSE}
library(knitr)
opts_chunk$set(comment="", message=FALSE,tidy.opts=list(keep.blank.line=TRUE, width.cutoff=120),options(width=100), cache=TRUE,fig.align='center',fig.height=6, fig.width=10,fig.path='figure/beamer-',fig.show='hold',size='footnotesize', cache=TRUE)
```

```{r}
library(xtable)
data(tli)
attach(tli)
x <- tli
fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data=x)
print(xtable(fm1), file="ta.tex", floating=FALSE)
print(xtable(head(tli, n=5)), file="tb.tex", floating=FALSE)
```

egin{table}[ht]
centering
subfloat[Table x(a)]{label{tab:tab1a}scalebox{.5}{input{./ta}}}quad
subfloat[Table x(b)]{label{tab:tab1b}scalebox{.5}{input{./tb}}}
caption{Caption about here}
label{tab:tab1}
end{table}

这里是 header2.tex 文件的代码,需要与 .Rmd 文件位于同一文件夹中:

And here is a code of header2.tex file that need to be in the same folder as .Rmd file:

usepackage{subfig}
usepackage{graphicx}

这篇关于Rmarkdown 中的并排 Xtables的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆