This function is used to insert mini plots into
flextable with function compose()
.
It should be used inside a call to as_paragraph()
.
Available plots are 'box', 'line', 'points', 'density'.
plot_chunk(
value,
width = 1,
height = 0.2,
type = "box",
free_scale = FALSE,
unit = "in",
...
)
a numeric vector, stored in a list column.
size of the resulting png file in inches
type of the plot: 'box', 'line', 'points' or 'density'.
Should scales be free (TRUE or FALSE, the default value).
unit for width and height, one of "in", "cm", "mm".
arguments sent to plot functions (see par()
)
This chunk option requires package officedown in a R Markdown context with Word output format.
PowerPoint cannot mix images and text in a paragraph, images are removed when outputing to PowerPoint format.
Other chunk elements for paragraph:
as_bracket()
,
as_b()
,
as_chunk()
,
as_equation()
,
as_highlight()
,
as_image()
,
as_i()
,
as_sub()
,
as_sup()
,
as_word_field()
,
colorize()
,
gg_chunk()
,
hyperlink_text()
,
linerange()
,
lollipop()
,
minibar()
library(data.table)
library(flextable)
z <- as.data.table(iris)
z <- z[ , list(
Sepal.Length = mean(Sepal.Length, na.rm = TRUE),
z = list(.SD$Sepal.Length)
), by = "Species"]
ft <- flextable(z,
col_keys = c("Species", "Sepal.Length", "box", "density"))
ft <- mk_par(ft, j = "box", value = as_paragraph(
plot_chunk(value = z, type = "box",
border = "red", col = "transparent")))
ft <- mk_par(ft, j = "density", value = as_paragraph(
plot_chunk(value = z, type = "dens", col = "red")))
ft <- set_table_properties(ft, layout = "autofit", width = .6)
ft <- set_header_labels(ft, box = "boxplot", density= "density")
theme_vanilla(ft)
#> a flextable object.
#> col_keys: `Species`, `Sepal.Length`, `box`, `density`
#> header has 1 row(s)
#> body has 3 row(s)
#> original dataset sample:
#> Species Sepal.Length
#> 1 setosa 5.006
#> 2 versicolor 5.936
#> 3 virginica 6.588
#> z
#> 1 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4.8, 4.8, 4.3, 5.8, 5.7, 5.4, 5.1, 5.7, 5.1, 5.4, 5.1, 4.6, 5.1, 4.8, 5.0, 5.0, 5.2, 5.2, 4.7, 4.8, 5.4, 5.2, 5.5, 4.9, 5.0, 5.5, 4.9, 4.4, 5.1, 5.0, 4.5, 4.4, 5.0, 5.1, 4.8, 5.1, 4.6, 5.3, 5.0
#> 2 7.0, 6.4, 6.9, 5.5, 6.5, 5.7, 6.3, 4.9, 6.6, 5.2, 5.0, 5.9, 6.0, 6.1, 5.6, 6.7, 5.6, 5.8, 6.2, 5.6, 5.9, 6.1, 6.3, 6.1, 6.4, 6.6, 6.8, 6.7, 6.0, 5.7, 5.5, 5.5, 5.8, 6.0, 5.4, 6.0, 6.7, 6.3, 5.6, 5.5, 5.5, 6.1, 5.8, 5.0, 5.6, 5.7, 5.7, 6.2, 5.1, 5.7
#> 3 6.3, 5.8, 7.1, 6.3, 6.5, 7.6, 4.9, 7.3, 6.7, 7.2, 6.5, 6.4, 6.8, 5.7, 5.8, 6.4, 6.5, 7.7, 7.7, 6.0, 6.9, 5.6, 7.7, 6.3, 6.7, 7.2, 6.2, 6.1, 6.4, 7.2, 7.4, 7.9, 6.4, 6.3, 6.1, 7.7, 6.3, 6.4, 6.0, 6.9, 6.7, 6.9, 5.8, 6.8, 6.7, 6.7, 6.3, 6.5, 6.2, 5.9
#> box density
#> 1
#> 2
#> 3