在Markdown中绘制图表周围的文字

sam*_*amz 4 r knitr r-markdown

我正在重新提出这个问题: 如何在R Markdown的情节中包装文字?:

'目前R中R Markdown的默认值是让一行文字与情节一致,但这看起来很尴尬,我想通过让文字环绕绘图来节省空间(图左对齐,文字环绕)正确的).'

Sam*_*uel 19

通过向 r 块添加两个参数,现在似乎有一种更简单的方法:

out.width= "65%", out.extra='style="float:right; padding:10px"'

这会将绘图缩放到页面宽度的 65%,并让文本在左侧浮动 10px 的距离。

  • 您将文本放在块之前还是之后? (3认同)
  • 对我来说,代码块后面的文本开始环绕图形。图形代码块之前的文本不会换行。另外,对我来说,这个解决方案不适用于“kable”表。 (2认同)
  • 我收到一条错误消息,提示样式未知。 (2认同)

Ian*_*ley 11

您可以使用CSS样式来定位您想要的元素.然而,可能存在一些困难,它确实需要一些调整.这是一个简单的例子:

---
title: "Untitled"
author: "Ian Wesley"
date: "April 21, 2017"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown
<div style= "float:right;position: relative; top: -80px;">
```{r pressure, echo=FALSE}
plot(pressure)
```
</div>

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Run Code Online (Sandbox Code Playgroud)

产量:

在此输入图像描述