These functions helps you quickly generate sets of sparkline
style plots using base R plotting system. Currently, we support histogram
and boxplot. You can use them together with column_spec
to
generate inline plot in tables. By default, this function will save images
in a folder called "kableExtra" and return the address of the file.
spec_hist(
x,
width = 200,
height = 50,
res = 300,
breaks = "Sturges",
same_lim = TRUE,
lim = NULL,
xaxt = "n",
yaxt = "n",
ann = FALSE,
col = "lightgray",
border = NULL,
dir = if (is_latex()) rmd_files_dir() else tempdir(),
file = NULL,
file_type = if (is_latex()) "png" else "svg",
...
)spec_boxplot(
x,
width = 200,
height = 50,
res = 300,
add_label = FALSE,
label_digits = 2,
same_lim = TRUE,
lim = NULL,
xaxt = "n",
yaxt = "n",
ann = FALSE,
col = "lightgray",
border = NULL,
boxlty = 0,
medcol = "red",
medlwd = 1,
dir = if (is_latex()) rmd_files_dir() else tempdir(),
file = NULL,
file_type = if (is_latex()) "png" else "svg",
...
)
Vector of values or List of vectors of values.
The width of the plot in pixel
The height of the plot in pixel
The resolution of the plot. Default is 300.
one of:
a vector giving the breakpoints between histogram cells,
a function to compute the vector of breakpoints,
a single number giving the number of cells for the histogram,
a character string naming an algorithm to compute the number of cells (see ‘Details’),
a function to compute the number of cells.
In the last three cases the number is a suggestion only; as the
breakpoints will be set to pretty
values, the number
is limited to 1e6
(with a warning if it was larger). If
breaks
is a function, the x
vector is supplied to it
as the only argument (and the number of breaks is only limited by
the amount of available memory).
T/F. If x is a list of vectors, should all the plots be plotted in the same range? Default is True.
Manually specify plotting range in the form of c(0, 10)
.
On/Off for xaxis text
On/Off for yaxis text
On/Off for annotations (titles and axis titles)
Color for the fill of the histogram bar/boxplot box.
Color for the border.
Directory of where the images will be saved.
File name. If not provided, a random name will be used
Graphic device. Support png
or svg
. SVG is recommended
for HTML output
further arguments and graphical parameters passed to
plot.histogram
and thence to title
and
axis
(if plot = TRUE
).
For boxplot. T/F to add labels for min, mean and max.
If T for add_label, rounding digits for the label. Default is 2.
Boxplot - box boarder type
Boxplot - median line color
Boxplot - median line width