Removing blank space from code chunks in .RMD (compiling knitr to Beamer pdf)
<p>I am creating slides on RStudio (Version 0.99.903) in an R Markdown .Rmd file, with output set to PDF (Beamer).  On several slides, I would like to insert a plot, either below text or alone on a slide, with the code producing the plot not viewable on the screen.  However, despite many things I've tried, there is always a space between the end of the text and the start of the figure, presumably where the code chunk would have appeared had I not set echo=FALSE.  For example:</p>

<pre><code>---
title: "Untitled"
author: "Math 35"
date: "October 14, 2016"
output: beamer_presentation
---

```{r setup, echo=FALSE, include=FALSE}
knitr::knit_hooks$set(mysize = function(before, options, envir) {
  if (before) 
    return(options$size)
})
knitr::opts_chunk$set(size='\\small')
knitr::opts_chunk$set(warning=FALSE)
knitr::opts_chunk$set(message=FALSE)
knitr::opts_chunk$set(fig.align='center')
```

## Recap from Last Time: Continuous Random Variables
-- Uniform Random Variable  $X\sim  U(a,b)$
$$f_X(x) = \frac{1}{b-a}, a \leq x \leq b$$
$$E[X] = \frac{a+b}{2}$$
$$Var(X) = \frac{(b-a)^2}{12}$$
```{r, echo=FALSE, fig.height=3, fig.width=3.5}
density &lt;- dunif(x=seq(from=0, to=6, by=0.01), min=1, max=5)
plot(seq(from=0, to=6, by=0.01), density, col="black", type="l", ylim=c(0, 0.5), lwd=4,  xlab="X ~ U(1,5)")
  lines(c(3,3), c(0,dunif(3, min=1, max=5)), col="red", lwd=2)
  text(2.9, 0.1, "E[X]=(1+5)/2 = 3", col="purple")
```
</code></pre>

<p>When I "Knit PDF" within R Studio, the slide that is produced has a large blank space between the text and the figure. As a result, the figure doesn't fit on the slide.  I would like to remove this blank space so that everything can fit on the slide.</p>

<p>Here are all the code chunk options I've tried that haven't worked:</p>

<ul>
<li><p>results='hide' which would ordinarily hide regular command results but still show the figure, but in this case still leaves the blank space.</p></li>
<li><p>strip.white=TRUE</p></li>
<li><p>tidy=TRUE</p></li>
<li><p>fig.keep = 'high'</p></li>
<li><p>fig.keep = 'last'</p></li>
<li><p>highlight= 'false'</p></li>
</ul>

<p>I've also looked at:</p>

<ul>
<li><p><a href="http://yihui.name/knitr/demo/output/" rel="nofollow">http://yihui.name/knitr/demo/output/</a>   which refers to <a href="https://github.com/yihui/knitr/issues/231" rel="nofollow">https://github.com/yihui/knitr/issues/231</a>  but since that addresses the problem in a .Rnw file, which I'm unfamiliar with, I couldn't get that solution to work.  I tried putting the suggested header at the top of the .Rmd file but "Knit PDF" didn't complete compiling. I probably did it wrong.</p></li>
<li><p>I've looked at the R Markdown reference guide which is where I found the various options I tried above.</p></li>
</ul>

<p>I've spent now two hours trying to figure out how to get one figure to show up properly on one slide.  Any help would be appreciated.</p>