ranimationknitrgridextraslidy

Resize videobox for animation in slidy presentation (RMarkdown)


I am making a presentation that contains an animation with a grid of plots in slidy (rmarkdown). The videobox is a bit too large for the slide and I would like to reduce it. My presentation is similiar to this one:

---
title: "Adbd"
output: slidy_presentation
---

## Animation

```{r animation1,echo=FALSE,fig.align='center', fig.show='animate', aniopts='controls,width=0.1', fig.height=9, fig.width=9,fig.retina=2}
for(i in 1:2){
  library(ggplot2)
  library(gridExtra)
  p1 <- ggplot(mtcars, aes(wt, mpg))+geom_point()+xlim(1,6)+ylim(9,35)
  p2 <- ggplot(mtcars, aes(wt, mpg))+geom_point()+xlim(1,8)+ylim(9,35)
  p3 <- ggplot(mtcars, aes(wt, mpg))+geom_point()+xlim(1,8)+ylim(6,35)
  p4 <- ggplot(mtcars, aes(wt, mpg, label=rownames(mtcars)))+geom_point()+xlim(1,8)+ylim(9,35)+ geom_text()

  grid.arrange(p1,p2,p3,p4, nrow=2, ncol=2) 
}
```

I would like to reduce the video tag's width from it's default value (864) to something like 650. I can easily do it in the .html, but, I rather change it from the .rmd document.

So far I tried:

Any help will be appreciated.


Solution

  • This works for me

    video {
      width:  650px  !important;
      height:  auto  !important;
    }
    

    You can also center the video if you want

    video { 
      display: block;
      margin: 0 auto;
    }
    

    Your rmd will look like

    ---
    title: "Adbd"
    output: slidy_presentation
    ---
    
    <style>
    
    video {
      width:  650px  !important;
      height:  auto  !important;
    
      /* center the player */
      display: block;
      margin: 0 auto;
    }
    
    </style>
    
    ## Animation
    
    ```{r animation1,echo=FALSE,fig.align='center', fig.show='animate', aniopts='controls,width=0.1', fig.height=9, fig.width=9,fig.retina=2}
    for(i in 1:2){
      library(ggplot2)
      library(gridExtra)
      p1 <- ggplot(mtcars, aes(wt, mpg))+geom_point()+xlim(1,6)+ylim(9,35)
      p2 <- ggplot(mtcars, aes(wt, mpg))+geom_point()+xlim(1,8)+ylim(9,35)
      p3 <- ggplot(mtcars, aes(wt, mpg))+geom_point()+xlim(1,8)+ylim(6,35)
      p4 <- ggplot(mtcars, aes(wt, mpg, label=rownames(mtcars)))+geom_point()+xlim(1,8)+ylim(9,35)+ geom_text()
    
      grid.arrange(p1,p2,p3,p4, nrow=2, ncol=2) 
    }
    ```