Knitr vary figure size in the same chunk

只愿长相守 提交于 2019-12-01 09:33:42
\documentclass{article}

\begin{document}

 <<Mwe, echo=FALSE, results = 'asis', message = F, warning = F>>=
library(knitr)
library(magrittr)

heights <- c(2.5, 8)

captions <- c("Caption 1", "Caption 2")

# Template for a plot chunk
template <- "<<plot-chunk-{{i}}, fig.height = {{ph}}, fig.cap = '{{pc}}', echo = FALSE>>=
    hist(rnorm(100))
@"

# Knit the chunk and cat() the results using knit, knit_expand
knitfun <- function(i) {
  knit_expand(text = template, i = i, ph = heights[i], pc = captions[i]) %>%
    knit(text = ., quiet = T) %>%
    cat()
}

invisible(lapply(1:2, knitfun))


@

\end{document}

I'm basing this answer on this response to a similar question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!