Learn R Programming

openxlsx2 (version 0.7)

wb_add_mschart: Add mschart object to an existing workbook

Description

Add mschart object to an existing workbook

Usage

wb_add_mschart(
  wb,
  sheet = current_sheet(),
  dims = NULL,
  graph,
  colOffset = 0,
  rowOffset = 0
)

Arguments

wb

a workbook

sheet

the sheet on which the graph will appear

dims

the dimensions where the sheet will appear

graph

mschart object

colOffset, rowOffset

startCol and startRow

See Also

wb_data()

Examples

Run this code
if (requireNamespace("mschart")) {
require(mschart)

## Add mschart to worksheet (adds data and chart)
scatter <- ms_scatterchart(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species")
scatter <- chart_settings(scatter, scatterstyle = "marker")

wb <- wb_workbook() %>%
 wb_add_worksheet() %>%
 wb_add_mschart(dims = "F4:L20", graph = scatter)

## Add mschart to worksheet and use available data
wb <- wb_workbook() %>%
  wb_add_worksheet() %>%
  wb_add_data(x = mtcars, dims = "B2")

# create wb_data object
dat <- wb_data(wb, 1, dims = "B2:E6")

# call ms_scatterplot
data_plot <- ms_scatterchart(
  data = dat,
  x = "mpg",
  y = c("disp", "hp"),
  labels = c("disp", "hp")
)

# add the scatterplot to the data
wb <- wb %>%
  wb_add_mschart(dims = "F4:L20", graph = data_plot)
}

Run the code above in your browser using DataLab