I'm using gganimate
for my animations with RStudio v 1.1.463.
My animations appear in the "Viewer" window instead of below the code chunk. When I read gganimate
documentation, I get the impression there's a way to have the animations appear in the source window.
For example, this chunk creates an image in the Viewer.
library(ggplot2)
library(gganimate)
ggplot(iris) +
aes(Petal.Width, Petal.Length) +
geom_point() +
transition_states(Species,
transition_length = 2,
state_length = 1)
On >= 1.2 versions of Rstudio, you can embed animations into .Rmd files if your render it as .mp4 (I can't tell if that is also the case with your version).
```{r, warning=FALSE, message=FALSE}
ibrary(ggplot2)
library(gganimate)
p <- ggplot(iris) +
aes(Petal.Width, Petal.Length) +
geom_point() +
transition_states(Species,
transition_length = 2,
state_length = 1)
animate(p, renderer = ffmpeg_renderer(format = "webm"))
```
2 Likes
Thanks! I tested and it works.
Is there a way to hide the output text? It writes this to my source window.
I tried suppressMessages()
and invisble()
but neither worked.
Input #0 , image2, from 'C:/Users/st2516/AppData/Local/Temp/RtmpQDJC4m/39c53b47337/gganim_plot%4d.png':
Duration: 00:00:04.00, start: 0.000000, bitrate: N/A
Stream #0:0: Video: png, pal8(pc), 480x480, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (png (native) -> vp9 (libvpx-vp9))
Press [q] to stop, [?] for help
[libvpx-vp9 @ 000000000032ac80] v1.7.0-1218-g2b838d908
Output #0 , webm, to 'C:\Users\st2516\AppData\Local\Temp\RtmpQDJC4m\file39c17891072.webm':
Metadata:
encoder : Lavf58.26.100
Stream #0:0: Video: vp9 (libvpx-vp9), yuv420p, 480x480, q=-1--1, 200 kb/s, 25 fps, 1k tbn, 25 tbc
Metadata:
encoder : Lavc58.46.100 libvpx-vp9
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 100 fps= 22 q=0.0 Lsize= 53kB time=00:00:03.96 bitrate= 109.7kbits/s speed=0.88x
video:52kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.527226%
That is weird, I didn't get any of that when running the chunk, try putting this in your chunks header
```{r, warning=FALSE, message=FALSE}
1 Like
system
Closed
February 18, 2019, 8:59pm
5
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.