flextable can embed graphics inside cells as chunk objects. Each graphic function returns a chunk that is passed toDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/davidgohel/flextable/llms.txt
Use this file to discover all available pages before exploring further.
as_paragraph() and then to compose() or mk_par().
All graphic chunks require the officedown package in an R Markdown context when the output format is Word. PowerPoint cannot mix images and text in a paragraph — image chunks are silently removed from PowerPoint output.
Horizontal bar: minibar()
minibar(value, max, barcol, bg, width, height, unit) draws a simple filled progress bar scaled to a maximum value:
| Parameter | Default | Description |
|---|---|---|
value | required | Numeric vector of bar values. |
max | max(value) | Value that maps to full width. |
barcol | "#CCCCCC" | Bar fill color. |
bg | "transparent" | Background color of the unfilled area. |
width | 1 | Width of the output image in inches (or unit). |
height | 0.2 | Height of the output image. |
unit | "in" | Unit for width and height: "in", "cm", or "mm". |
Range plot: linerange()
linerange(value, min, max, rangecol, stickcol, bg, width, height, raster_width, unit) draws a line with end-stops and a vertical marker at the value’s position:
| Parameter | Default | Description |
|---|---|---|
value | required | Numeric vector of positions to mark. |
min | min(value) | Left end of the range axis. |
max | max(value) | Right end of the range axis. |
rangecol | "#CCCCCC" | Color of the range line and end-stops. |
stickcol | "#FF0000" | Color of the position marker. |
bg | "transparent" | Background. |
width | 1 | Output image width. |
height | 0.2 | Output image height. |
raster_width | 30 | Number of pixels used when interpolating the position. |
unit | "in" | Unit for width and height. |
ggplot2 plots: gg_chunk()
gg_chunk(value, width, height, unit, res) renders a ggplot2 object stored in a list column as a PNG and embeds it:
| Parameter | Default | Description |
|---|---|---|
value | required | List column of ggplot2 objects. |
width | 1 | Output image width. |
height | 0.2 | Output image height. |
unit | "in" | Unit for width and height. |
res | 300 | PNG resolution in ppi. |
Base R plots: plot_chunk()
plot_chunk(value, width, height, type, free_scale, unit, ...) renders a list column of numeric vectors as small base R plots:
type accepts "box", "line", "points", or "density". Additional ... arguments are forwarded to the underlying base R plot function.
Grid graphics: grid_chunk()
grid_chunk(value, width, height, unit, res) embeds grid graphical objects (grobs):
Embedding images: as_image()
as_image(src, width, height, unit, guess_size) reads an image file and embeds it as a chunk:
guess_size = TRUE (the default) and magick is installed, flextable reads the image dimensions automatically so you don’t need to specify width and height.
Row height
Mini graphics expand the rendered PNG to the cell, but the row must be tall enough to display them. Useheight() to set explicit row heights, or autofit() after composing to let flextable adjust automatically:
Output format considerations
- Word
- HTML
- PDF
- PowerPoint
- Graphic chunks require the officedown package.
- Images and text can coexist in the same paragraph.
- Use
widthandheightvalues that match the physical size you want in the printed document.