title: Display animated plot using gganimate in knitr Markdown for ioslides presentation: root directory
body: <p>I want to embed a plot produced with ggplot and gganimate into a slideshow using knitr. I can produce animation when data and .Rmd file in same folder. </p>
  
  <p>Here is a reproducible example for animation. </p>
  
  <pre><code>```{r setup, include=FALSE}
  knitr::opts_chunk$set(echo = FALSE)
  library(ggplot2)
  library(gganimate)
  library(gapminder)
  ```
  
  ## Static plot create
  ```{r, }
  ranim &lt;- ggplot(gapminder, aes(x = gdpPercap,y=lifeExp, 
                                    size = pop,
                                    colour = country)) +
        geom_point(show.legend = FALSE, alpha = 0.7) +
        scale_color_viridis_d() +
        scale_size(range = c(2, 12)) +
        scale_x_log10() +
     labs(x = "GDP per capita", y = "Life expectancy")
  ```
  
  ## Static plot
  ```{r, }
  ranim
  ```
  
  ## Build animate
  ```{r, }
  ranim2 &lt;- ranim + 
  transition_time(year) + 
  labs(title = "Year: {frame_time}")
  ```
  
  ## View animate
  ```{r, }
  animate(ranim2)
  ```
  </code></pre>
  
  <p>However, the problem occurs when I used local data saved into a subfolder. I open a project in a folder 'Project1'. I save data in a subfolder 'Data'. I set the options to root directory into the data folder. </p>
  
  <pre><code>knitr::opts_knit$set(root.dir = './Data')
  </code></pre>
  
  <p>My .Rmd file is saved in the folder Project1. The code is below and produces a blank slide when I compile. I can produce the animated file in the Viewer by running the code chunk manually from the .Rmd. But when the html compiles it's blank. </p>
  
  <p>Is there a recommended setup for organizing local data in project subfolder and producing markdown slides from .Rmd saved in main Project1 folder? </p>
  
  <pre><code>```{r setup, include=FALSE}
  knitr::opts_chunk$set(echo = FALSE)
  knitr::opts_knit$set(root.dir = './Data')
  library(ggplot2)
  library(gganimate)
  library(gapminder)
  ```
  
  ## slide 1
  ```{r, }
  datain &lt;- read.csv("table1.csv")
  panim &lt;- ggplot(datain, aes(x, y, frame = year)) + geom_point()
  ```
  
  ## Static plot view
  ```{r, }
  panim
  ```
  
  ## Static plot add animate
  ```{r, }
  panim2 &lt;- panim + transition_time(year) + 
  labs(title = "Year: {frame_time}")
  ```
  
  ## Activate animate 
  ```{r, }
  animate(panim2)
  ```
  </code></pre>