Plot animation in knitr rmarkdown

前端 未结 1 1175
春和景丽
春和景丽 2021-01-04 12:14

Problem:

Hi, I try to make an animated plot in a rmarkdown document. Here is my code:

```{r lmSim, fig.show=\'animate\'}
library(animation)
library(p         


        
相关标签:
1条回答
  • 2021-01-04 12:55

    Have you tried with ggplot and gganimation? For example:

    library(gapminder)
    library(gganimate)
    library(ggplot)
    
    head(gapminder)
    theme_set(theme_bw())
    
    p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = 1, color = continent, frame = year)) +
      geom_point() +
      scale_x_log10()
    
    
    animation<-gganimate(p, "your_animation.gif")#Or to your path
    

    See that you need to save first your animation. You need to have establish your work directory.

    After you can call it from the chat or html in markdown (not from the R chuck) like:

    ![your caption here](your_animation.gif)
    
    0 讨论(0)
提交回复
热议问题