Search code examples
positionr-markdownfigure

figure before, not after #Discussion - R Markdown


I am having an issue positioning a figure.

My header:

\usepackage{amsmath}
\usepackage{pdflscape}
\newcommand{\blandscape}{\begin{landscape}}
\newcommand{\elandscape}{\end{landscape}}

Some of my R Markdown code:

\newpage
\blandscape
```{r finaltable1_1, echo=FALSE}
table1_1
```
\elandscape

\newpage
\blandscape
```{r figone, message=FALSE, warning=FALSE, echo=FALSE, out.width='100%', fig.align='center', fig.cap='description.'}
knitr::include_graphics('./images/figure2.pdf')
```
\elandscape

\newpage
```{r figresults, message=FALSE, warning=FALSE, echo=FALSE, out.width='100%', fig.align='center', fig.cap='description.'}
knitr::include_graphics('./images/figure3.pdf')
```

\newpage
# Discussion

figure3 should go before Discussion, but it is showing after, any ideas about what might be happening?


Solution

  • So, you can solve your problem by:

    a) reducing the pic's width in this chunk:

    ```{r figresults, message=FALSE, warning=FALSE, echo=FALSE, out.width='70%', fig.align='center', fig.cap='description.'}
    knitr::include_graphics('pic.pdf')
    ```
    

    b) using another constructions:

    ![My piccy-pic](pic.pdf){width=90%}
    

    or

    \begin{figure}[H]
    \centering
    \includegraphics[width=0.9\textwidth]{pic.pdf}
    \caption{I'm here}
    \end{figure}