img <- system.file("extdata", "example.png", package = "officer")
if (nzchar(img) && file.exists(img)) {
x <- read_xlsx()
x <- add_sheet(x, label = "pics")
x <- sheet_add_drawing(
x, sheet = "pics",
value = external_img(img, width = 2, height = 2)
)
print(x, target = tempfile(fileext = ".xlsx"))
}
if (requireNamespace("ggplot2", quietly = TRUE)) {
gg <- ggplot2::ggplot(iris, ggplot2::aes(Sepal.Length, Sepal.Width)) +
ggplot2::geom_point()
x <- read_xlsx()
x <- add_sheet(x, label = "plots")
x <- sheet_add_drawing(x, value = gg, sheet = "plots",
width = 4, height = 3)
print(x, target = tempfile(fileext = ".xlsx"))
}
Run the code above in your browser using DataLab