Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support {mschart} #412

Closed
wants to merge 23 commits into from
Closed

Support {mschart} #412

wants to merge 23 commits into from

Conversation

JanMarvin
Copy link
Owner

@JanMarvin JanMarvin commented Nov 12, 2022

Corresponding PR to write mschart charts to openxlsx2 workbooks.

ardata-fr/mschart#79

library(mschart)
library(openxlsx2)

# write data starting at B2
wb <- wb_workbook()$add_worksheet()$
  add_data(x = mtcars, dims = "B2")$
  add_data(x = data.frame(name = rownames(mtcars)), dims = "A2")

# create wb_data object this will tell this mschart from this PR to create a file corresponding to openxlsx2
dat <- wb_data(wb, 1, dims = "A2:G6")

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

bar_plot <- ms_barchart(
  data = dat,
  x = "name",
  y = c("disp", "hp"),
  labels = c("disp", "hp")
)

area_plot <- ms_areachart(
  data = dat,
  x = "name",
  y = c("disp", "hp"),
  labels = c("disp", "hp")
)

line_plot <- ms_linechart(
  data = dat,
  x = "name",
  y = c("disp", "hp"),
  labels = c("disp", "hp")
)

# add the scatterplots to the data
wb <- wb %>% 
  wb_add_mschart(dims = "F4:L20", graph = scatter_plot) %>%
  wb_add_mschart(dims = "F21:L37", graph = bar_plot) %>%
  wb_add_mschart(dims = "M4:S20", graph = area_plot) %>%
  wb_add_mschart(dims = "M21:S37", graph = line_plot)

wb$open()

Screenshot 2022-11-26 at 15 55 02

Copy link
Owner Author

@JanMarvin JanMarvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Various things to do

R/wb_functions.R Show resolved Hide resolved
R/wb_functions.R Show resolved Hide resolved
R/class-workbook.R Show resolved Hide resolved
R/wb_functions.R Show resolved Hide resolved
R/wb_functions.R Outdated Show resolved Hide resolved
R/class-workbook-wrappers.R Show resolved Hide resolved
<cs:variation><a:lumMod val=\"50000\"/><a:lumOff val=\"50000\"/></cs:variation>
</cs:colorStyle>"

stylebarplot_xml <- paste0('<cs:chartStyle xmlns:cs="http://schemas.microsoft.com/office/drawing/2012/chartStyle" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" id="201">
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style plot or are barplots somehow special?

R/baseXML.R Outdated Show resolved Hide resolved
R/baseXML.R Show resolved Hide resolved
@JanMarvin JanMarvin changed the title [WIP] Mschart2 Support mschart Nov 26, 2022
@JanMarvin JanMarvin added the Third party 📦 Using or impacting external library or software label Nov 29, 2022
@JanMarvin JanMarvin changed the title Support mschart Support {mschart} Nov 29, 2022
@JanMarvin
Copy link
Owner Author

Could use add_drawing code from #449

This was referenced Nov 30, 2022
@JanMarvin JanMarvin closed this Dec 3, 2022
@JanMarvin JanMarvin deleted the mschart2 branch December 5, 2022 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 😀 New feature or request Third party 📦 Using or impacting external library or software
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant