使用gganimate将内容编织到pdf文档(不包括动画)

时间:2018-10-19 00:40:52

标签: r pdf-generation r-markdown knitr gganimate

我正在尝试使用gganimate软件包生成一个包含动画情节的pdf文档。我正在关注Thomas Lin Pedersen example

---
title: "PDF Animation Test"
output: pdf_document
header-includes:
   - \usepackage{animate}
---

`gganimate` now supports animations inside PDF documents. This feature is only 
viewable with Acrobat Reader, however. Remember to include 
`\usepackage{animate}` in the preamble and set `fig.show='animate'` in the chunk
options. Further, the framerate is governed by `interval`rather than any 
`gganimate` settings:

```{r, fig.show='animate', interval=1/10}
library(gganimate)
ggplot(airquality, aes(Day, Temp, group = Month)) + 
  geom_line() + 
  transition_reveal(Month, Day)
```

当我编织为.pdf并使用Acrobat Reader阅读该文档时,该pdf不包含动画。这是编织文档后得到的输出:

processing file: pdf.Rmd
  |................................                                 |  50%
  ordinary text without R code

  |.................................................................| 100%
label: unnamed-chunk-1 (with options) 
List of 2
 $ fig.show: chr "animate"
 $ interval: language 1/10

executing: ffmpeg -y -r 10 -i pdf_files/figure-latex/unnamed-chunk-1-%d.pdf -b:v 1M -crf 10 pdf_files/figure-latex/unnamed-chunk-1.webm
ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
pdf_files/figure-latex/unnamed-chunk-1-%d.pdf: No such file or directory

/usr/bin/pandoc +RTS -K512m -RTS pdf.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pdf.tex --template /home/atai/R/x86_64-pc-linux-gnu-library/3.5/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in' --variable 'compact-title:yes' 
output file: pdf.knit.md


Output created: pdf.pdf

一开始,我认为我的Pandoc版本是1.19.2.1版,所以我将其更新为2.3.1版。但是,这并不能解决问题。

我的会话信息:

~$ pandoc -v
pandoc 2.3.1

sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS

1 个答案:

答案 0 :(得分:2)

我认为Thomas忘记提及此功能需要 knitr 的开发版本:

devtools::install_github('yihui/knitr')