THis function was written to make it easy to knit figures with different, or dynamically generated, widths and heights (and captions) in the same chunk when working with R Markdown.
knitFig(
plotToDraw,
template = getOption("ufs.knitFig.template", NULL),
figWidth = ufs::opts$get("ggSaveFigWidth"),
figHeight = ufs::opts$get("ggSaveFigHeight"),
figCaption = "A plot.",
chunkName = NULL,
returnRaw = FALSE,
catPlot = ufs::opts$get("knitFig.catPlot"),
...
)
This function returns nothing, but uses knit_expand
and knit
to cat
the result.
The plot to draw, e.g. a ggplot
plot.
A character value with the knit_expand
template to use.
The width to set for the figure (in inches).
The height to set for the figure (in inches).
The caption to set for the figure.
Optionally, the name for the chunk. To avoid problems
because multiple chunks have the name "unnamed-chunk-1
", if no chunk
name is provided, digest::digest()
is used to generate an MD5-hash from
Sys.time
.
Whether to cat()
the result (TRUE
) or whether
to return it as knitr::asis_output()
object (FALSE
).
Whether to use the base::cat()
function to print the
code for the plot, and return the result invisibly. If not, the result is
returned visible, and so probably printed anyway.
Any additional arguments are passed on to
knit_expand
.
Gjalt-Jorn Peters
Maintainer: Gjalt-Jorn Peters gjalt-jorn@userfriendlyscience.com
knit_expand
and knit
if (FALSE) knitFig(ggBoxplot(mtcars, 'mpg'))
Run the code above in your browser using DataLab