Learn R Programming

openxlsx2 (version 1.4)

wb_add_mschart: Add mschart object to a worksheet

Description

Add mschart object to a worksheet

Usage

wb_add_mschart(
  wb,
  sheet = current_sheet(),
  dims = NULL,
  graph,
  col_offset = 0,
  row_offset = 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

col_offset, row_offset

offsets for column and row

...

additional arguments

See Also

wb_data() wb_add_chart_xml() wb_add_image wb_add_mschart() wb_add_plot

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