我正在尝试使用knitr和pandoc转换为PDF时控制绘图的位置.我的.Rmd文件看起来像这样:
# My report
Some text some text some text some text some text some text some text some text some text
```{r myplot, echo=FALSE, fig.pos="placeHere", results='hide'}
library(ggplot2)
ggplot(mtcars, aes(mpg, drat)) + geom_point()
```
Some text some text some text some text some text some text some text some text some text
\usepackage{graphicx}
\begin{figure}[placeHere]
\centering
\includegraphics[width=0.5\textwidth]{placeHere}
\end{figure}
Some text some text some text some text some text some text some text some text some text
Run Code Online (Sandbox Code Playgroud)
我正在使用此处提供的功能转换为PDF:http://quantifyingmemory.blogspot.co.uk/2013/02/reproducible-research-with-r-knitr.html
如何在第二和第三块文本之间放置图?乳胶代码目前无法正常工作. …
我想在texmaker中使用knitr将标题放在图上方. 我知道这个问题已经被提出,我理解到目前为止建议的解决方案是使用:
\begin{figure}
\caption{This is a caption above the figure}
<<a-plot, echo=FALSE>>=
plot(1)
@
\end{figure}
Run Code Online (Sandbox Code Playgroud)
但是这样我就无法显示代码(因为echo=FALSE).如果我选择echo=TRUE,我得到的是标题,然后是代码,然后是图表,这也不是我想要的.我想要展示的是代码R,(和)用该R代码绘制的图表,图表上方的标题.
在 RMarkdown 中编织到 HTML 时,是否可以将标题移动到我的图形上方?似乎在 PDF 中是可能的,即在编织到 PDF 时,但我不知道如何为 HTML 复制它。我正在使用bookdown数字编号。
当我运行这样的东西时:
```{r fig.cap= "caption"}
df <- data.frame(letter = letters[1:5], value = 1)
ggplot(df, aes(as(factor(1), value, fill = letters))) +
geom_bar(stat = "identity")
```
Run Code Online (Sandbox Code Playgroud)
标题显示在图的底部,但我想将其显示在图的上方。
我想知道如何让我的标题出现在 R Markdown 中的图形上方。
这是一个工作示例:
---
title: "Practical"
output:
pdf_document:
fig_caption: yes
latex_engine: xelatex
---
```{r fig1, echo=FALSE, fig.cap="\\label{fig:fig1}Caption"}
x <- 1:10
y <- 11:20
plot(x, y)
```
Run Code Online (Sandbox Code Playgroud)
这个问题之前已经在这里提出过,但建议的代码似乎对我不起作用。