r - Figure position in markdown when converting to PDF with knitr and pandoc -
i'm trying control position of plot when converting pdf using knitr , pandoc. .rmd file looks this:
# report text text text text text text text text text ```{r myplot, echo=false, fig.pos="placehere", results='hide'} library(ggplot2) ggplot(mtcars, aes(mpg, drat)) + geom_point() ``` text text text text text text text text text \usepackage{graphicx} \begin{figure}[placehere] \centering \includegraphics[width=0.5\textwidth]{placehere} \end{figure} text text text text text text text text text
i'm converting pdf using functions provided here: http://quantifyingmemory.blogspot.co.uk/2013/02/reproducible-research-with-r-knitr.html
how can place plot between second , third blocks of text? latex code not working stands.
edit: i'm trying now.
# report ```{r setup, include=false} # set global chunk options opts_chunk$set(cache=false) library(ggplot2) ``` ```{r, echo=false, fig.height=3} ggplot(mtcars, aes(disp, hp)) + geom_point() ``` text text text text text text text text text text text text text text text text text text text textsome text text text text text text text text text text text text text text text text text text text text text text textsome text text text text text text text text text text text text text text text text text text text text text text textsome text text text text text text text text text text text text text text text text text text text text text text textsome text text text ```{r, echo=false, fig.height=3} ggplot(mtcars, aes(vs, am)) + geom_point() ``` text text text text text text text text text text text text text text text text text text text textsome text text text text text text text text text text text text text text text text text text text text text text textsome text text text text text text text text text text text text text text text text text text text text text text textsome text text text ```{r, echo=false, fig.height=6} ggplot(mtcars, aes(disp, cyl)) + geom_point() ``` ```{r, echo=false, fig.height=6} ggplot(mtcars, aes(hp, qsec)) + geom_point() ``` text text text text text text text text text text text text text text text text text text text textsome text text text ```{r, echo=false, fig.height=3} ggplot(mtcars, aes(hp, wt)) + geom_point() ``` text text text text text text text text text text text text text text text text text text text textsome text text text ```{r, echo=false, fig.height=5} ggplot(mtcars, aes(mpg, drat)) + geom_point() ``` text text text text text text text text text text text text text text text text text text text textsome text text text
i'm not aware of such option pandoc
set floating option of figures when converting markdown document latex. if choose markdown simplicity, should not expect power it, powerful tools pandoc
. bottom line: markdown not latex. designed html instead of latex.
two ways go:
use rnw syntax (r + latex) instead of rmd (r markdown) (examples); able use chunk option
fig.pos='h'
after\usepackage{float}
in preamble; in case, have full power of latex, , pandoc not involvedhack @ latex document generated pandoc, e.g. like
library(knitr) knit('foo.rmd') # gives foo.md pandoc('foo.md', format='latex') # gives foo.tex x = readlines('foo.tex') # insert float package x = sub('(\\\\begin\\{document\\})', '\\\\usepackage{float}\n\\1', x) # add h option figures x = gsub('(\\\\begin\\{figure\\})', '\\1[h]', x) # write processed tex file writelines(x, 'foo.tex') # compile pdf tools::texi2pdf('foo.tex') # gives foo.pdf
if not these solutions, consider requesting new feature pandoc on github, sit , wait.
Comments
Post a Comment