1

I'm trying to get my plot to appear immediately underneath my code. I've seen two other questions like this.

Figure position in markdown when converting to PDF with knitr and pandoc

Position of plots using knitr

These each have many suggestions, some of them very complicated, but none have worked. The suggested answer from Yihui: https://yihui.name/knitr/options/ is

fig.show: ('asis'; character) how to show/arrange the plots; four possible values are asis: show plots exactly in places where they were generated (as if the code were run in an R terminal);

but that also doesn't work. This is my current attempt. If you knit it as an html, the figures show up in the right places but lose their captions. Is there something extra that I need to install? Or additional code?

---
title: "Plotting Plots Under Code"
author: "Ilana"
date: "February 1, 2017"
output: pdf_document
fig.show: "asis"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
```

## Title

```{r fig.cap="Sample Plots"}

plot(iris$Sepal.Length,iris$Petal.Length,main="First One")
plot(iris$Sepal.Length,iris$Petal.Length,main="Second One")
#Where I want figure two
plot(iris$Sepal.Length,iris$Petal.Length,main="Third One")

```

More Text, Which should be on the bottom of the document

Thank you

Community
  • 1
  • 1
  • The second answer of the first question does work for me (http://stackoverflow.com/a/33801326/1777111) – Martin Schmelzer Feb 01 '17 at 21:21
  • My full header, attempting to implement that method. title: "Untitled" author: "Ilana" date: "February 1, 2017" output: pdf_document rmarkdown::pdf_document: fig_caption: yes includes: in_header: preamble-latex.tex In the tex file, all I included was the code he posted: \usepackage{float} \let\origfigure\figure \let\endorigfigure\endfigure \renewenvironment{figure}[1][2] { \expandafter\origfigure\expandafter[H] } { \endorigfigure } I didn't put a tex header with document class or anything. Did you? – Ilana Urman Feb 01 '17 at 21:44
  • Are you sure that the indentation of the YAML is correct? Only difference to my attempt: I used `output: pdf_document` without `rmarkdown::` – Martin Schmelzer Feb 01 '17 at 21:54
  • Switching it to pdf_document (without rmarkdown) worked!! Perfect. My question is answered. I'm new to stack exchange: how do I close the question? – Ilana Urman Feb 01 '17 at 22:16
  • The community takes care of it. Marked it as a duplicate. – Martin Schmelzer Feb 01 '17 at 22:17

0 Answers0