有没有办法,在knitr中将fig.cap移到图上方?我需要它们,以便当为某个表选择了图表列表的超链接时,它会导航到该图.现在标题和超链接目标位于底部,所以当选择时,只有标题显示在页面顶部,并且必须向上滚动才能看到图...相当愚蠢.
我当前代码的示例:
<<Race, fig.lp='fig:', fig=TRUE, eval=TRUE, echo=FALSE, dev='png', fig.pos='H', fig.width=8, fig.height=4, fig.cap='Race', fig.align='center', dpi=300>>=
b <- ggplot(melt(race.plot, id=c("Type"), variable.name="Race", value.name="Count"))
b + geom_bar(aes(Race, y=Count, fill=Race), position="dodge", stat="identity", alpha=0.7) +
ggtitle("Race") + xlab("") + ylab("Count") +
facet_wrap(~Type, nrow=2, scale="free_y") +
theme(plot.title=element_text(size=25),
axis.title=element_text(size=15),
axis.text.y=element_text(size=10),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())
@
Run Code Online (Sandbox Code Playgroud)
我知道有很多方法可以使用乳胶并将fig.cap单独留在knitr chunk中:
\begin{figure}
\caption{This is a caption above the figure}
<<a-plot, echo=FALSE>>=
plot(1)
@
\end{figure}
Run Code Online (Sandbox Code Playgroud)
大多数建议都是为了做到这一点,但是大约在2012年或2013年初.我想知道knitr的任何更改是否允许此功能.
我一直在使用knitr和xtable中的选项来控制输出中的大部分内容但是什么是共识?我是否应该尽可能避免这种情况并在编织块之外使用乳胶选项?
在 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)
这个问题之前已经在这里提出过,但建议的代码似乎对我不起作用。