Inserts an image into a new worksheet, optionally with title, source, and metadata. Images must be provided either as a ggplot object or as a path to the image file.
insert_worksheet_image(
wb,
sheetname,
image,
title = NULL,
source = NULL,
metadata = NULL,
width = NULL,
height = NULL,
startrow = 3,
startcol = 3,
units = "in",
dpi = 300
)
workbook object to write new worksheet in
Name of the sheet where the image should be inserted
Image, either a ggplot object or the path to an existing image.
Title of the image. Can be NULL
Source associated with the image. Can be NULL.
Metadata associated with the image. Can be NULL.
width of figure
height of figure
row coordinate of upper left corner of figure
column coordinate of upper left corner of figure
unit of measurement (default: in)
image resolution (default: 300)
The function does not write the result into a .xlsx file. A separate call to openxlsx::saveWorkbook() is required. A temporary file is created for inputs of type gg, ggplot or histogram object at path given by `tempfile()`.
figure <- ggplot2::ggplot(mtcars, ggplot2::aes(x = disp)) +
ggplot2::geom_histogram()
wb <- openxlsx::createWorkbook()
insert_worksheet_image(wb, sheetname = "ggplot image",
image = figure, width = 3.5, height = 5.5)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.