Depending on the options passed over, hook_plot_tex may return the
normal \includegraphics{} command, or \input{} (for tikz
files), or \animategraphics{} (for animations); it also takes many
other options into consideration to align plots and set figure sizes, etc.
Similarly, hook_plot_html, hook_plot_md and
hook_plot_rst return character strings which are HTML, Markdown, reST
code.
For animations (i.e. when the chunk option fig.show is 'animate'),
hook_plot_tex generates \animategraphics{} unless a hook function
has been provided via the chunk option animation.hook or the package option
animation.fun, in which case that function generates the LaTeX code instead.
It is called only once per chunk, with the filename of the last plot. The
built-in hooks (e.g. hook_ffmpeg_html()) generate HTML, and are
ignored for LaTeX output.
In most cases we do not need to call these hooks explicitly, and they were
designed to be used internally. Sometimes we may not be able to record R
plots using grDevices::recordPlot(), and we can make use of
these hooks to insert graphics output in the output document; see
hook_plot_custom() for details.