Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphics on next slide with ioslides using Rstudio's Rmd

I want to have my graph output display on the next slide while the code chunk stays on the first. I am using the default ioslides in Rstudio. I would think that it would be some attribute of the code chunk but I can't figure out what it is.

---
output: ioslides_presentation
---

## Slide with Plot

```{r, echo=TRUE}
plot(cars)
```

Any one have any idea on how to do this in Rstudio?

I want to use this for educational purposes. First showing the code and than revealing the graph. Now I am stuck with doing double code chunks with echo=FALSE and TRUE and eval=FALSE and TRUE.

like image 508
Sharon Avatar asked Jan 18 '15 15:01

Sharon


2 Answers

It's easier to run the code twice, once not evaluating the code, the second time not showing the code.

---
title: "Plot Separation"
output: ioslides_presentation
---

## Plot 1

```{r, eval = FALSE}
plot(1:10)
```

## Plot 2

```{r, echo = FALSE}
plot(1:10)
```

It also avoids the error when smaller is true.

like image 186
Dario Avatar answered Sep 28 '22 01:09

Dario


To move a plot to the next slide, you need to add a horizontal rule ---- before it (see documentation). You can modify the default plot hook to do it:

```{r setup, include=FALSE}
library(knitr)
local({
  hook_plot = knit_hooks$get('plot')
  knit_hooks$set(plot = function(x, options) {
    paste0('\n\n----\n\n', hook_plot(x, options))
  })
})
```
like image 44
Yihui Xie Avatar answered Sep 28 '22 02:09

Yihui Xie