hook_plot: Default plot hooks for different output formats

Description Usage Arguments Details Value References See Also Examples

Description

These hook functions define how to mark up graphics output in different output formats.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11

Arguments

x

Filename for the plot (a character string).

options

A list of the current chunk options.

Details

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.

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 recordPlot, and we can make use of these hooks to insert graphics output in the output document; see hook_plot_custom for details.

Value

A character string of code, with plot filenames wrapped.

References

https://yihui.name/knitr/hooks/

See Also

hook_plot_custom

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# this is what happens for a chunk like this

# <<foo-bar-plot, dev='pdf', fig.align='right'>>=
hook_plot_tex("foo-bar-plot.pdf", opts_chunk$merge(list(fig.align = "right")))

# <<bar, dev='tikz'>>=
hook_plot_tex("bar.tikz", opts_chunk$merge(list(dev = "tikz")))

# <<foo, dev='pdf', fig.show='animate', interval=.1>>=

# 5 plots are generated in this chunk
hook_plot_tex("foo5.pdf", opts_chunk$merge(list(fig.show = "animate", interval = 0.1, 
    fig.cur = 5, fig.num = 5)))

yihui/knitr documentation built on Dec. 14, 2018, 6:22 p.m.