addImage: addImage

View source: R/xlsxTools.R

addImageR Documentation

addImage

Description

Insert either an existing image or the current plot into a worksheet.

Usage

addImage(
  onesheet,
  image,
  line,
  col,
  wide = 7,
  high = 4,
  unit = "in",
  spec.dpi = 300,
  wb = NULL
)

Arguments

onesheet

A sheet object from openXlsx package

image

The filename of a previously saved image (format supported: jpeg, bmp, png) or the name of the image in the current R environment

line

The line where to paste the image

col

The column where to paste the image

wide

Size of the image (in unit)

high

Size of the image (in unit)

unit

For wide and high, default is "in" (Inch) "cm" or "px"

spec.dpi

300 by default

wb

An optional wb if not already opened

Value

Nothing

Author(s)

Jenny Howard, Marine Maurel

See Also

openxlsx::insertImage(), openxlsx::insertPlot()

Examples

## Not run:  
addImage(onesheet = cells, 
          image = graphname, 
          line = 2, 
          col = 2, 
          wb = template) 

## End(Not run)

# Usage 1: Insert existing image saved as a PNG file
xls_file <- externalFile("excelfile.xlsx")
openXlsx(xls_file)
cells <- openSheet("T2")
image_file <- externalFile("image_xlsx.png")
addImage(onesheet = cells, image = image_file, line = 20, col = 2)

# Usage 2: Insert current plot
## Not run: 
image_gg <- ggplot(Orange, 
                   aes(x = age, y = circumference, colour = as.factor(Tree))) +
                   geom_point() + 
                   geom_line() +
                   labs(colour = "Tree") + 
                   theme_minimal()
addImage(onesheet = cells, image = image_gg, line = 20, col = 2)

## End(Not run)
       

Epiconcept-Paris/STRAP-epiuf documentation built on Aug. 5, 2024, 3:41 a.m.