无法为 knitr / R Markdown 中的并排图复制 MWE(HTML 输出)
Can't replicate MWE for side-by-side plots in knitr / R Markdown (HTML output)
我在 Knitr+Latex 中找到了 this MWE 的并排图,我尝试使用 HTML 输出将其转换为 R Markdown。这是我试过的:
```{r, fig.show='hold', fig.width=3, fig.height=2.5, out.width=".49\textwidth"}
par(mar = c(4, 4, .1, .1), cex.lab = .95, cex.axis = .9, mgp = c(2, .7, 0), tcl = -.3)
plot(cars)
boxplot(cars$dist,xlab='dist')
```
然而它似乎什么都没有。我在尝试复制 this other MWE 时也遇到了同样的问题。
我的设置有问题吗?我怎样才能使它与 HTML 而不仅仅是 PDF 一起工作?
编辑:使用 mfrow
或以其他方式干扰图形设备本身不是一种选择,因为我正在使用的绘图功能 (filled.contour
) 不幸地接管了 layout
。
out.width
指令把事情搞砸了。当你不在 LaTeX 输出模式时,out.width="0.49\textwidth"
是没有意义的......(你所指的另一个 MWE 也是 LaTeX 风格——我不知道你做了什么使它适应 HTML ...)
writeLines("
```{r, fig.show='hold', fig.width=3, fig.height=2.5}
par(mar = c(4, 4, .1, .1), cex.lab = .95,
cex.axis = .9, mgp = c(2, .7, 0), tcl = -.3)
plot(cars)
boxplot(cars$dist,xlab='dist')
```
",con="figtest.rmd")
rmarkdown::render("figtest.rmd")
browseURL("figtest.html")
似乎工作正常。
如果您需要更好地控制放置,您可能需要嵌入一些 HTML 指令——例如
<table><tr><td>
## chunk with first figure code
</td><td>
## chunk with second figure code
</td></tr></table>
我发现了问题:我启用了 fig.align='center'
。显然,这与将两个地块放在同一条线上的能力有某种冲突。
我在 Knitr+Latex 中找到了 this MWE 的并排图,我尝试使用 HTML 输出将其转换为 R Markdown。这是我试过的:
```{r, fig.show='hold', fig.width=3, fig.height=2.5, out.width=".49\textwidth"}
par(mar = c(4, 4, .1, .1), cex.lab = .95, cex.axis = .9, mgp = c(2, .7, 0), tcl = -.3)
plot(cars)
boxplot(cars$dist,xlab='dist')
```
然而它似乎什么都没有。我在尝试复制 this other MWE 时也遇到了同样的问题。
我的设置有问题吗?我怎样才能使它与 HTML 而不仅仅是 PDF 一起工作?
编辑:使用 mfrow
或以其他方式干扰图形设备本身不是一种选择,因为我正在使用的绘图功能 (filled.contour
) 不幸地接管了 layout
。
out.width
指令把事情搞砸了。当你不在 LaTeX 输出模式时,out.width="0.49\textwidth"
是没有意义的......(你所指的另一个 MWE 也是 LaTeX 风格——我不知道你做了什么使它适应 HTML ...)
writeLines("
```{r, fig.show='hold', fig.width=3, fig.height=2.5}
par(mar = c(4, 4, .1, .1), cex.lab = .95,
cex.axis = .9, mgp = c(2, .7, 0), tcl = -.3)
plot(cars)
boxplot(cars$dist,xlab='dist')
```
",con="figtest.rmd")
rmarkdown::render("figtest.rmd")
browseURL("figtest.html")
似乎工作正常。
如果您需要更好地控制放置,您可能需要嵌入一些 HTML 指令——例如
<table><tr><td>
## chunk with first figure code
</td><td>
## chunk with second figure code
</td></tr></table>
我发现了问题:我启用了 fig.align='center'
。显然,这与将两个地块放在同一条线上的能力有某种冲突。