Helper function that splits up a single written R chunk (in R Markdown) into multiple subchunks. This can be used to enable plotting multiple plots of different sizes and captions from within a single written R code chunk in R Markdown.

subchunkify(
  g,
  i,
  fig_height = 12,
  fig_width = 10,
  caption = "''",
  add_class = NULL,
  other_args = ""
)

Arguments

g

Plot or object to display in R Markdown output.

i

Chunk id. Should be unique for each plot or subchunk.

fig_height

Height of plot or output of subchunk (in inches). See fig.height in the knitr chunk options.

fig_width

Width of plot or output of subchunk (in inches). See fig.width in the knitr chunk options.

caption

Figure or subchunk caption. Should be surrounded by two sets of quotes, e.g., "'This is a valid caption.'" See fig.cap in the knitr chunk options.

add_class

Vector of css classes to add to object.

other_args

Other arguments to pass to knitr chunk header. Should be surrounded by two sets of quotes, e.g., "results='asis'".

References

Adapted from Michael James Williams.