### Create data frame for chart_table example Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_table.Rd Builds the sample dataset used in the chart_table example, containing factor columns for supp and dose, a numeric length column, and a label column. ```R data <- data.frame( supp = factor(rep(c("OJ", "VC"), each = 3), levels = c("OJ", "VC")), dose = factor(rep(c("low", "medium", "high"), 2), levels = c("low", "medium", "high")), length = c(13.23, 22.7, 24.06, 7.98, 16.77, 26.14), label = LETTERS[1:6], stringsAsFactors = FALSE ) ``` -------------------------------- ### Install development version from GitHub Source: https://github.com/ardata-fr/mschart/blob/main/README.md Installs the development version of the mschart package directly from GitHub using devtools. ```r devtools::install_github("ardata-fr/mschart") ``` -------------------------------- ### Create a bar chart with ms_barchart() Source: https://github.com/ardata-fr/mschart/blob/main/README.md Basic example showing how to create a bar chart using the mschart package. The data frame 'sales' contains quarter, revenue, and region columns, and the chart groups by region. ```r library(mschart) sales <- data.frame( quarter = rep(c("Q1", "Q2", "Q3", "Q4"), each = 2), revenue = c(12, 9, 15, 11, 18, 14, 21, 17), region = rep(c("EU", "US"), times = 4) ) bars <- ms_barchart( data = sales, x = "quarter", y = "revenue", group = "region" ) ``` -------------------------------- ### Install latest version from CRAN Source: https://github.com/ardata-fr/mschart/blob/main/README.md Installs the latest stable version of the mschart package from CRAN. ```r install.packages("mschart") ``` -------------------------------- ### Create a histogram chart with ms_histogramchart Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_histogramchart.Rd Builds a histogram chart from raw numeric observations and inserts it into a PowerPoint slide. The example sets a seed, generates 200 normal samples, creates the chart with 12 bins, then adds it to a new slide and saves to a temporary file. ```R library(officer) set.seed(1) dat <- data.frame(x = rnorm(200, mean = 10, sd = 4)) hi <- ms_histogramchart(dat, value = "x", bin_count = 12) doc <- read_pptx() doc <- add_slide(doc) doc <- ph_with(doc, hi, location = ph_location_fullsize()) print(doc, target = tempfile(fileext = ".pptx")) ``` -------------------------------- ### Set X axis limits and intervals with chart_ax_x Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_ax_x.Rd Creates a line chart and then adjusts the x-axis major unit and time unit. The example also sets y-axis limits and intervals using chart_ax_y. Requires the mschart package and the us_indus_prod dataset. ```R library(mschart) chart_01 <- ms_linechart( data = us_indus_prod, x = "date", y = "value", group = "type" ) chart_01 <- chart_ax_y(x = chart_01, limit_min = 20, limit_max = 120) chart_01 # control axis intervals chart_01 <- chart_ax_x(chart_01, major_unit = 10, major_time_unit = "years" ) chart_01 <- chart_ax_y(chart_01, major_unit = 20) chart_01 ``` -------------------------------- ### Create areachart with custom theme (ms_areachart, mschart_theme) Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_areachart.Rd Sets up a custom chart theme with red bold x-axis title, green italic y-axis title, orange major grid lines and ticks, then creates an areachart from browser_ts data grouped by browser. Applies axis formatting with chart_ax_y and chart_ax_x, and sets the theme with set_theme. ```R library(officer) mytheme <- mschart_theme( axis_title_x = fp_text(color = "red", font.size = 24, bold = TRUE), axis_title_y = fp_text(color = "green", font.size = 12, italic = TRUE), grid_major_line_y = fp_border(width = 1, color = "orange"), axis_ticks_y = fp_border(width = 1, color = "orange") ) # example ac_01 ------- ac_01 <- ms_areachart( data = browser_ts, x = "date", y = "freq", group = "browser" ) ac_01 <- chart_ax_y(ac_01, cross_between = "between", num_fmt = "General") ac_01 <- chart_ax_x(ac_01, cross_between = "midCat", num_fmt = "m/d/yy") ac_01 <- set_theme(ac_01, mytheme) ``` -------------------------------- ### Create a radar chart with ms_radarchart Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_radarchart.Rd Builds a radar (spider) chart from a data frame with a grouping column. The example reshapes wide data into long format, then passes it to ms_radarchart with x, y, and group arguments. The resulting ms_chart object can be inserted into a Microsoft document. ```R library(officer) dat <- data.frame( axis = c("Sales", "Marketing", "Dev", "Support", "HR"), s1 = c(4, 3, 5, 2, 4), s2 = c(3, 5, 2, 4, 3) ) dat_long <- data.frame( axis = rep(dat$axis, 2), value = c(dat$s1, dat$s2), group = rep(c("Team A", "Team B"), each = 5) ) radar <- ms_radarchart( data = dat_long, x = "axis", y = "value", group = "group" ) radar ``` -------------------------------- ### Change grouping to percentStacked (chart_settings) Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_areachart.Rd Creates a variant of the areachart (ac_01) with grouping set to "percentStacked", producing a percentage-stacked area chart. ```R # example ac_02 ------- ac_02 <- chart_settings(ac_01, grouping = "percentStacked") ``` -------------------------------- ### ms_areachart(data, x, y, group = NULL, labels = NULL, asis = FALSE) Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_areachart.Rd Creates an areachart object that can be inserted into a Microsoft document. Area charts plot change over time and show the relationship of parts to a whole. ```APIDOC ## ms_areachart(data, x, y, group = NULL, labels = NULL, asis = FALSE) ### Description Creates an areachart object that can be inserted into a Microsoft document. Area charts plot change over time and show the relationship of parts to a whole. ### Usage ms_areachart(data, x, y, group = NULL, labels = NULL, asis = FALSE) ### Parameters - **data** (data.frame) - Required - A data.frame. - **x** (column name) - Required - Column name for x values. - **y** (column name) - Required - Column name for y values. - **group** (column name) - Optional - Grouping column name used to split data into series. - **labels** (column names) - Optional - Column names of columns to be used as custom data labels displayed next to data points (not axis labels). If more than one name is provided, only the first one will be used as a label, but all labels (transposed if a group is used) will be available in the Excel file associated with the chart. - **asis** (logical) - Optional - Defaults to FALSE. When FALSE, the data is reshaped internally so that each series becomes a separate column. When TRUE, the data is used as-is and must already have one column for categories and one column per series, and `y` accepts a vector of series column names. `asis` describes the *input shape* read by the constructor. Not to be confused with the `write_data` argument of `sheet_add_drawing.ms_chart()`, which controls whether `mschart` writes the chart's data into an Excel sheet at embed time. The two are independent. ### Return Value An `ms_chart` object. ### Examples ```r library(officer) mytheme <- mschart_theme( axis_title_x = fp_text(color = "red", font.size = 24, bold = TRUE), axis_title_y = fp_text(color = "green", font.size = 12, italic = TRUE), grid_major_line_y = fp_border(width = 1, color = "orange"), axis_ticks_y = fp_border(width = 1, color = "orange") ) # example ac_01 ------- ac_01 <- ms_areachart( data = browser_ts, x = "date", y = "freq", group = "browser" ) ac_01 <- chart_ax_y(ac_01, cross_between = "between", num_fmt = "General") ac_01 <- chart_ax_x(ac_01, cross_between = "midCat", num_fmt = "m/d/yy") ac_01 <- set_theme(ac_01, mytheme) # example ac_02 ------- ac_02 <- chart_settings(ac_01, grouping = "percentStacked") # example ac_03 ------- ac_03 <- chart_settings(ac_01, grouping = "percentStacked", table = TRUE) ac_03 <- chart_table( ac_03, horizontal = FALSE, vertical = FALSE, outline = FALSE, show_keys = TRUE) ``` ### See Also `chart_settings()`, `chart_ax_x()`, `chart_ax_y()`, `chart_data_labels()`, `chart_theme()`, `chart_labels()` Other 'Office' chart objects: `ms_barchart()`, `ms_boxplotchart()`, `ms_bubblechart()`, `ms_chart_combine()`, `ms_funnelchart()`, `ms_histogramchart()`, `ms_linechart()`, `ms_paretochart()`, `ms_piechart()`, `ms_radarchart()`, `ms_scatterchart()`, `ms_stockchart()`, `ms_sunburstchart()`, `ms_treemapchart()`, `ms_waterfallchart()` ``` -------------------------------- ### Set Y axis settings with chart_ax_y Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_ax_y.Rd Use this example to configure a y axis on an ms_chart object. It creates a line chart from us_indus_prod, applies the 'marker' style, and sets the x axis number format and limits. The chart_ax_y function is the S3 generic for y axis settings; the default method accepts parameters like orientation, crosses, tick marks, and limits. ```R library(officer) library(mschart) chart_01 <- ms_linechart( data = us_indus_prod, x = "date", y = "value", group = "type" ) chart_01 <- chart_settings(chart_01, style = "marker") chart_01 <- chart_ax_x( x = chart_01, num_fmt = "[$-fr-FR]mmm yyyy", limit_min = min(us_indus_prod$date), limit_max = as.Date("1992-01-01") ) chart_01 ``` -------------------------------- ### Create a horizontal percentage stacked barchart with as_bar_stack Source: https://github.com/ardata-fr/mschart/blob/main/man/as_bar_stack.Rd Builds an ms_barchart and applies as_bar_stack with percent = TRUE and dir = "horizontal" to display bars as percentages horizontally. ```R my_bar_stack_02 <- ms_barchart(data = browser_data, x = "browser", y = "value", group = "serie") my_bar_stack_02 <- as_bar_stack( my_bar_stack_02, percent = TRUE, dir = "horizontal" ) ``` -------------------------------- ### Create a custom chart theme with mschart_theme() Source: https://github.com/ardata-fr/mschart/blob/main/man/set_theme.Rd Builds a theme object with red bold axis titles, orange major Y grid lines, and gray Y axis ticks. Requires the officer package for fp_text() and fp_border(). ```R library(officer) mytheme <- mschart_theme( axis_title = fp_text(color = "red", font.size = 24, bold = TRUE), grid_major_line_y = fp_border(width = 1, color = "orange"), axis_ticks_y = fp_border(width = 0.4, color = "gray") ) ``` -------------------------------- ### Example: chart_data_size with scatter chart Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_data_size.Rd Complete example creating a scatter chart from iris data and applying fill, stroke, symbol, and size mappings per species. The size values are 20, 16, and 20 for virginica, versicolor, and setosa respectively. ```r my_scatter <- ms_scatterchart(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") my_scatter <- chart_data_fill(my_scatter, values = c(virginica = "#6FA2FF", versicolor = "#FF6161", setosa = "#81FF5B") ) my_scatter <- chart_data_stroke(my_scatter, values = c(virginica = "black", versicolor = "black", setosa = "black") ) my_scatter <- chart_data_symbol(my_scatter, values = c(virginica = "circle", versicolor = "diamond", setosa = "circle") ) my_scatter <- chart_data_size(my_scatter, values = c(virginica = 20, versicolor = 16, setosa = 20) ) ``` -------------------------------- ### chart_data_symbol usage example with ms_scatterchart Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_data_symbol.Rd Example from the chart_data_symbol Rd documentation. Creates a scatter chart from the iris dataset, then applies chart_data_fill, chart_data_stroke, and chart_data_symbol to customize series appearance. The symbol values are named by species: virginica and setosa use 'circle', versicolor uses 'diamond'. ```r my_scatter <- ms_scatterchart(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") my_scatter <- chart_data_fill(my_scatter, values = c(virginica = "#6FA2FF", versicolor = "#FF6161", setosa = "#81FF5B") ) my_scatter <- chart_data_stroke(my_scatter, values = c(virginica = "black", versicolor = "black", setosa = "black") ) my_scatter <- chart_data_symbol(my_scatter, values = c(virginica = "circle", versicolor = "diamond", setosa = "circle") ) ``` -------------------------------- ### Set line styles for scatter chart series with chart_data_line_style Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_data_line_style.Rd Example from the chart_data_line_style Rd file showing how to create a scatter chart and apply line styles per series using a named vector. The values are matched by series names and can be 'none', 'solid', 'dashed', or 'dotted'. The example also applies fill, stroke, and symbol styles before setting line styles. ```R my_scatter <- ms_scatterchart(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") my_scatter <- chart_data_fill(my_scatter, values = c(virginica = "#6FA2FF", versicolor = "#FF6161", setosa = "#81FF5B") ) my_scatter <- chart_data_stroke(my_scatter, values = c(virginica = "black", versicolor = "black", setosa = "black") ) my_scatter <- chart_data_symbol(my_scatter, values = c(virginica = "circle", versicolor = "diamond", setosa = "circle") ) my_scatter <- chart_data_line_style(my_scatter, values = c(virginica = "solid", versicolor = "dotted", setosa = "dashed") ) ``` -------------------------------- ### Create stacked barchart with custom theme and data labels Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_barchart.Rd Builds a stacked barchart from browser_data with a custom theme, axis formatting, data labels, and per-series fill, stroke, and line width. The final print call is commented out. ```R # example chart 03 ------- mytheme <- mschart_theme( axis_title_x = fp_text(color = "gray", font.size = 20, bold = TRUE), axis_title_y = fp_text(color = "gray", font.size = 20, italic = TRUE), grid_major_line_y = fp_border(width = 1, color = "wheat"), axis_ticks_y = fp_border(width = 1, color = "gray") ) chart_03 <- ms_barchart( data = browser_data, x = "browser", y = "value", group = "serie" ) chart_03 <- chart_settings(chart_03, grouping = "stacked", gap_width = 150, overlap = 100 ) chart_03 <- chart_ax_x(chart_03, cross_between = "between", major_tick_mark = "out", minor_tick_mark = "none" ) chart_03 <- chart_ax_y(chart_03, num_fmt = "0.00", minor_tick_mark = "none" ) chart_03 <- set_theme(chart_03, mytheme) chart_03 <- chart_labels(x = chart_03, title = "Things in percent") chart_03 <- chart_data_labels(chart_03, position = "ctr", show_val = TRUE ) chart_03 <- chart_labels_text(chart_03, fp_text(color = "white", bold = TRUE, font.size = 9) ) chart_03 <- chart_data_fill(chart_03, values = c( serie1 = "#4477AA", serie2 = "#CC6677", serie3 = "#DDCC77" ) ) chart_03 <- chart_data_stroke(chart_03, values = c( serie1 = "#223B55", serie2 = "#66333C", serie3 = "#6F663C" ) ) chart_03 <- chart_data_line_width(chart_03, values = c(serie1 = 2, serie2 = 2, serie3 = 2) ) ``` -------------------------------- ### Create barchart with wide-format input using asis = TRUE Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_barchart.Rd Builds a barchart from wide-format data where each series is its own column. Pass the series column names as a vector in `y` and set `asis = TRUE`. The commented `print(chart_08, preview = TRUE)` line shows how to preview the chart. ```R # example chart 08 ------- # Wide-format input: each series is its own column. Pass the series # column names as a vector in `y` and set `asis = TRUE`. browser_wide <- data.frame( browser = unique(browser_data$browser), serie1 = browser_data$value[browser_data$serie == "serie1"], serie2 = browser_data$value[browser_data$serie == "serie2"], serie3 = browser_data$value[browser_data$serie == "serie3"] ) chart_08 <- ms_barchart( data = browser_wide, x = "browser", y = c("serie1", "serie2", "serie3"), asis = TRUE ) # print(chart_08, preview = TRUE) ``` -------------------------------- ### Create pie and doughnut charts with ms_piechart Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_piechart.Rd Loads officer and mschart, builds a data.frame of browser shares, then creates a pie chart with ms_piechart and chart_labels, and a doughnut chart using chart_settings with hole_size = 50. Data must be pre-aggregated with one row per slice and no grouping column. ```R library(officer) library(mschart) dat <- data.frame( browser = c("Chrome", "Firefox", "Safari", "Edge", "Other"), value = c(64, 12, 8, 5, 11) ) # Pie chart pie <- ms_piechart(data = dat, x = "browser", y = "value") pie <- chart_labels(pie, title = "Browser share") # Doughnut chart donut <- ms_piechart(data = dat, x = "browser", y = "value") donut <- chart_settings(donut, hole_size = 50) donut <- chart_labels(donut, title = "Browser share (donut)") ``` -------------------------------- ### Apply custom theme with set_theme Source: https://github.com/ardata-fr/mschart/blob/main/man/set_theme.Rd Creates a bar chart and applies a custom theme object (mytheme) using set_theme(). The chart is configured with horizontal direction, stacked grouping, gap_width = 150, and overlap = 100. ```R my_bc <- ms_barchart( data = browser_data, x = "browser", y = "value", group = "serie" ) my_bc <- chart_settings(my_bc, dir = "horizontal", grouping = "stacked", gap_width = 150, overlap = 100 ) my_bc <- set_theme(my_bc, mytheme) ``` -------------------------------- ### Add data table to percentStacked areachart (chart_settings, chart_table) Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_areachart.Rd Builds on ac_01 with percentStacked grouping and enables a chart data table, then customizes the table with chart_table: horizontal and vertical lines off, outline off, and keys shown. ```R # example ac_03 ------- ac_03 <- chart_settings(ac_01, grouping = "percentStacked", table = TRUE) ac_03 <- chart_table( ac_03, horizontal = FALSE, vertical = FALSE, outline = FALSE, show_keys = TRUE) ``` -------------------------------- ### mschart_theme(...) Source: https://github.com/ardata-fr/mschart/blob/main/man/set_theme.Rd Creates a chart theme object with formatting properties for various chart elements. Returns an mschart_theme object. ```APIDOC ## mschart_theme(...) ### Description Creates a chart theme object with formatting properties for various chart elements. Returns an mschart_theme object. ### Usage mschart_theme( axis_title = fp_text(bold = TRUE, font.size = 16), axis_title_x = axis_title, axis_title_y = axis_title, main_title = fp_text(bold = TRUE, font.size = 20), legend_text = fp_text(font.size = 14), table_text = fp_text(bold = FALSE, font.size = 9), axis_text = fp_text(), axis_text_x = axis_text, axis_text_y = axis_text, title_rot = 0, title_x_rot = 0, title_y_rot = 270, axis_ticks = fp_border(color = "#99999999"), axis_ticks_x = axis_ticks, axis_ticks_y = axis_ticks, grid_major_line = fp_border(color = "#99999999", style = "dashed"), grid_major_line_x = grid_major_line, grid_major_line_y = grid_major_line, grid_minor_line = fp_border(width = 0), grid_minor_line_x = grid_minor_line, grid_minor_line_y = grid_minor_line, chart_background = NULL, chart_border = fp_border(color = "transparent"), plot_background = NULL, plot_border = fp_border(color = "transparent"), date_fmt = "yyyy/mm/dd", str_fmt = "General", double_fmt = "#,##0.00", integer_fmt = "0", legend_position = "b", legend_x = NULL, legend_y = NULL, legend_w = NULL, legend_h = NULL ) ### Arguments - **axis_title, axis_title_x, axis_title_y** - Required - Axis title formatting properties (see officer::fp_text()). - **main_title** - Required - Title formatting properties (see officer::fp_text()). - **legend_text** - Required - Legend text formatting properties (see officer::fp_text()). - **table_text** - Required - Table text formatting properties (see officer::fp_text()). - **axis_text, axis_text_x, axis_text_y** - Required - Axis text formatting properties (see officer::fp_text()). - **title_rot, title_x_rot, title_y_rot** - Required - Rotation angle. - **axis_ticks, axis_ticks_x, axis_ticks_y** - Required - Axis ticks formatting properties (see officer::fp_border()). - **grid_major_line, grid_major_line_x, grid_major_line_y** - Required - Major grid lines formatting properties (see officer::fp_border()). - **grid_minor_line, grid_minor_line_x, grid_minor_line_y** - Required - Minor grid lines formatting properties (see officer::fp_border()). - **chart_background** - Optional - Chart area background fill color - single character value (e.g. "#000000" or "black"). - **chart_border** - Required - Chart area border lines formatting properties (see officer::fp_border()). - **plot_background** - Optional - Plot area background fill color - single character value (e.g. "#000000" or "black"). - **plot_border** - Required - Plot area border lines formatting properties (see officer::fp_border()). - **date_fmt** - Required - Date format. - **str_fmt** - Required - String or factor format. - **double_fmt** - Required - Double format. - **integer_fmt** - Required - Integer format. - **legend_position** - Required - It specifies the position of the legend. It should be one of 'b', 'tr', 'l', 'r', 't', 'n' (for 'none'). - **legend_x, legend_y, legend_w, legend_h** - Optional - Optional fractions between 0 and 1 to manually position and size the legend box within the chart area. Each value is a fraction of the chart width (legend_x, legend_w) or height (legend_y, legend_h). Any NULL value keeps the default automatic layout; setting at least one triggers manual placement via . ### Value An mschart_theme object. ``` -------------------------------- ### Create a line chart with data table and table formatting Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_linechart.Rd Builds a line chart with the same data and y-axis settings as chart_02, adds data labels, enables the chart data table, and configures the table to show horizontal lines, hide vertical lines, show outline, and hide keys. ```R # example chart 03 ------- chart_03 <- ms_linechart( data = data, x = "dose", y = "length", group = "supp", labels = "label" ) chart_03 <- chart_ax_y( x = chart_03, cross_between = "between", limit_min = 5, limit_max = 30, num_fmt = "General" ) chart_03 <- chart_data_labels( x = chart_03, position = "l" ) chart_03 <- chart_settings( x = chart_03, table = TRUE ) chart_03 <- chart_table(chart_03, horizontal = TRUE, vertical = FALSE, outline = TRUE, show_keys = FALSE ) ``` -------------------------------- ### Set marker stroke colours for an ms_scatterchart Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_data_stroke.Rd Example from the chart_data_stroke Rd documentation. Creates a scatter chart from the iris dataset, applies fill colours per species with chart_data_fill, then sets the marker stroke colour to black for all species using chart_data_stroke with a named vector. ```R my_scatter <- ms_scatterchart(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") my_scatter <- chart_data_fill(my_scatter, values = c(virginica = "#6FA2FF", versicolor = "#FF6161", setosa = "#81FF5B") ) my_scatter <- chart_data_stroke(my_scatter, values = c(virginica = "black", versicolor = "black", setosa = "black") ) ``` -------------------------------- ### Create a vertical stacked barchart with as_bar_stack Source: https://github.com/ardata-fr/mschart/blob/main/man/as_bar_stack.Rd Builds an ms_barchart from browser_data and applies as_bar_stack with default settings (vertical direction, no percentages, gap_width 50). Requires the officer package. ```R library(officer) my_bar_stack_01 <- ms_barchart(data = browser_data, x = "browser", y = "value", group = "serie") my_bar_stack_01 <- as_bar_stack( my_bar_stack_01 ) ``` -------------------------------- ### Smooth line series with chart_data_smooth Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_data_smooth.Rd Use chart_data_smooth() to enable or disable line smoothing per series for an ms_linechart() object. The values argument is a named integer vector where 0 disables smoothing and 1 enables it; names must match series names. This example disables smoothing for all three iris species. ```R linec <- ms_linechart(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") linec <- chart_data_smooth(linec, values = c(virginica = 0, versicolor = 0, setosa = 0) ) ``` -------------------------------- ### Apply chart_settings to ms_barchart Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_settings.Rd Creates a bar chart with chart_theme and applies chart_settings with grouping='stacked' and overlap=100. ```R library(mschart) library(officer) chart_01 <- ms_barchart( data = browser_data, x = "browser", y = "value", group = "serie" ) chart_01 <- chart_theme(chart_01, grid_major_line_x = fp_border(width = 0), grid_minor_line_x = fp_border(width = 0) ) chart_02 <- chart_settings( x = chart_01, grouping = "stacked", overlap = 100 ) ``` -------------------------------- ### Apply ggplot2 color scale with chart_fill_ggplot2 Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_fill_ggplot2.Rd Applies the default hue color scale from ggplot2 to a mschart object. The stroke parameter defaults to TRUE, meaning the color scale is also applied to stroke. The example creates a scatter chart from the iris dataset, applies the ggplot2 theme, then applies the color scale. ```r p <- ms_scatterchart( data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species" ) p <- theme_ggplot2(p) p <- chart_fill_ggplot2(p) ``` -------------------------------- ### chart_data_fill example with ms_scatterchart Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_data_fill.Rd Creates a scatter chart from the iris dataset and applies named fill colours per species. The values vector maps series names to colours; a single colour would apply to all series. By default, update_stroke is TRUE so the stroke colour is also updated, except for series with a 'transparent' stroke. ```R my_scatter <- ms_scatterchart(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") my_scatter <- chart_data_fill(my_scatter, values = c(virginica = "#6FA2FF", versicolor = "#FF6161", setosa = "#81FF5B") ) ``` -------------------------------- ### as_bar_stack(x, dir = "vertical", percent = FALSE, gap_width = 50) Source: https://github.com/ardata-fr/mschart/blob/main/man/as_bar_stack.Rd Applies settings to an ms_barchart object to produce a stacked barchart. Options are available to use percentage instead of values and to choose if bars should be vertically or horizontally drawn. ```APIDOC ## as_bar_stack(x, dir = "vertical", percent = FALSE, gap_width = 50) ### Description Applies settings to an `ms_barchart` object to produce a stacked barchart. Options are available to use percentage instead of values and to choose if bars should be vertically or horizontally drawn. ### Usage ```r as_bar_stack(x, dir = "vertical", percent = FALSE, gap_width = 50) ``` ### Arguments - **x** (ms_barchart) - Required - An `ms_barchart` object. - **dir** (character) - Optional - The direction of the bars in the chart, value must be one of "horizontal" or "vertical". - **percent** (logical) - Optional - Should bars be displayed as percentages. - **gap_width** (numeric) - Optional - Gap width between bars for each category on a bar chart, as a percentage of the bar width. It can be set between 0 and 500. ### Value An `ms_chart` object. ### Examples ```r library(officer) my_bar_stack_01 <- ms_barchart(data = browser_data, x = "browser", y = "value", group = "serie") my_bar_stack_01 <- as_bar_stack( my_bar_stack_01 ) my_bar_stack_02 <- ms_barchart(data = browser_data, x = "browser", y = "value", group = "serie") my_bar_stack_02 <- as_bar_stack( my_bar_stack_02, percent = TRUE, dir = "horizontal" ) doc <- read_pptx() doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme") doc <- ph_with(doc, my_bar_stack_02, location = ph_location_fullsize()) fileout <- tempfile(fileext = ".pptx") print(doc, target = fileout) ``` ### See Also `chart_settings()`, `ms_barchart()` ``` -------------------------------- ### chart_settings(ms_chart_ex) Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_settings.Rd Fallback method for chartEx types that expose no settings (funnel, histogram, sunburst, treemap, waterfall). Replaces the default 'no applicable method' error with a discoverable message. ```APIDOC ## chart_settings(ms_chart_ex) ### Description Fallback method for chartEx types that expose no settings (funnel, histogram, sunburst, treemap, waterfall). Replaces the default 'no applicable method' error with a discoverable message. ### Method chart_settings ### Signature chart_settings(x, ...) ### Parameters - **x** (ms_chart_ex) - Required - An ms_chart object. - **...** - Optional - Unused parameter. ### Returns An ms_chart object. ``` -------------------------------- ### Create a line chart with grouped data and customize axes, stroke, line width, and theme Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_linechart.Rd Builds a line chart from us_indus_prod with date on x and value on y, grouped by type. Applies a French date format, sets axis limits, customizes series stroke colors and line widths, and removes major/minor grid lines on the x-axis. ```R library(officer) # example chart_01 ------- chart_01 <- ms_linechart( data = us_indus_prod, x = "date", y = "value", group = "type" ) chart_01 <- chart_ax_x( x = chart_01, num_fmt = "[$-fr-FR]mmm yyyy", limit_min = min(us_indus_prod$date), limit_max = as.Date("1992-01-01") ) chart_01 <- chart_data_stroke( x = chart_01, values = c(adjusted = "red", unadjusted = "gray") ) chart_01 <- chart_data_line_width( x = chart_01, values = c(adjusted = 2, unadjusted = 5) ) chart_01 <- chart_theme(chart_01, grid_major_line_x = fp_border(width = 0), grid_minor_line_x = fp_border(width = 0) ) ``` -------------------------------- ### Set line width per series with chart_data_line_width Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_data_line_width.Rd Example from the chart_data_line_width Rd file showing how to build a scatter chart and then apply per-series line widths with chart_data_line_width(values = c(virginica = 2, versicolor = 3, setosa = 6)). The values argument is a named vector matched by series names; a single value applies to all series. Returns an ms_chart object. ```R my_scatter <- ms_scatterchart(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") my_scatter <- chart_settings(my_scatter, style = "lineMarker") my_scatter <- chart_data_fill(my_scatter, values = c(virginica = "#6FA2FF", versicolor = "#FF6161", setosa = "#81FF5B") ) my_scatter <- chart_data_stroke(my_scatter, values = c(virginica = "black", versicolor = "black", setosa = "black") ) my_scatter <- chart_data_symbol(my_scatter, values = c(virginica = "circle", versicolor = "diamond", setosa = "circle") ) my_scatter <- chart_data_size(my_scatter, values = c(virginica = 20, versicolor = 16, setosa = 20) ) my_scatter <- chart_data_line_width(my_scatter, values = c(virginica = 2, versicolor = 3, setosa = 6) ) ``` -------------------------------- ### Create and insert a Pareto chart with ms_paretochart Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_paretochart.Rd Builds a Pareto chart from a data.frame of defects, adds it to a PowerPoint slide, and saves the file. Uses aggregate=TRUE (default) with long-format data; Office counts occurrences of each x value. Requires the officer package and Office 2016+ for the chartEx pipeline. ```r library(officer) set.seed(1) dat <- data.frame( defect = sample(c("A", "B", "C", "D"), 50, replace = TRUE, prob = c(0.5, 0.25, 0.15, 0.1)) ) pa <- ms_paretochart(dat, x = "defect") doc <- read_pptx() doc <- add_slide(doc) doc <- ph_with(doc, pa, location = ph_location_fullsize()) print(doc, target = tempfile(fileext = ".pptx")) ``` -------------------------------- ### Add stacked barchart to PowerPoint presentation Source: https://github.com/ardata-fr/mschart/blob/main/man/as_bar_stack.Rd Creates a PowerPoint document, adds a slide with the stacked barchart my_bar_stack_02, and saves it to a temporary file. Requires the officer package. ```R doc <- read_pptx() doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme") doc <- ph_with(doc, my_bar_stack_02, location = ph_location_fullsize()) fileout <- tempfile(fileext = ".pptx") print(doc, target = fileout) ``` -------------------------------- ### Create clustered vertical barchart with axis settings Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_barchart.Rd Builds a clustered vertical barchart from browser_data with custom axis tick marks and cross_between settings. The final print call is commented out. ```R # example chart 01 ------- chart_01 <- ms_barchart( data = browser_data, x = "browser", y = "value", group = "serie" ) chart_01 <- chart_settings( x = chart_01, dir = "vertical", grouping = "clustered", gap_width = 50 ) chart_01 <- chart_ax_x( x = chart_01, cross_between = "between", major_tick_mark = "out" ) chart_01 <- chart_ax_y( x = chart_01, cross_between = "midCat", major_tick_mark = "in" ) # print(chart_01, preview = TRUE) ``` -------------------------------- ### Create HLC stock chart with ms_stockchart Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_stockchart.Rd Builds a High-Low-Close stock chart from a data frame with date, high, low, and close columns. The open argument is omitted to produce an HLC chart. The resulting ms_chart object can be inserted into a Microsoft document. ```R library(officer) dat <- data.frame( date = as.Date("2024-01-01") + 0:4, open = c(44, 25, 38, 50, 34), high = c(55, 57, 57, 58, 58), low = c(11, 12, 13, 11, 25), close = c(32, 35, 34, 35, 43) ) # HLC chart stock_hlc <- ms_stockchart( data = dat, x = "date", high = "high", low = "low", close = "close" ) stock_hlc ``` -------------------------------- ### print.ms_chart(x, preview = FALSE, ...) Source: https://github.com/ardata-fr/mschart/blob/main/man/print.ms_chart.Rd Print method for ms_chart objects. It displays simple information about the object, or optionally previews the chart in a PowerPoint document. ```APIDOC ## print.ms_chart(x, preview = FALSE, ...) ### Description Print method for ms_chart objects. Displays simple information about the object, or if `preview` is TRUE, produces a pptx file and opens it with `browseURL`. ### Method print ### Signature `print.ms_chart(x, preview = FALSE, ...)` ### Parameters - **x** (ms_chart) - Required - An `ms_chart` object. - **preview** (logical) - Optional - If TRUE, preview the chart in a PowerPoint document. - **...** - Optional - Unused. ### Return Value No return value, called for side effects. ``` -------------------------------- ### ms_piechart(data, x, y, labels = NULL) Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_piechart.Rd Creates a piechart object that can be inserted into a Microsoft document. Pie charts show the proportion of each category as a slice of a circle; doughnut charts are similar but have a hole in the centre, controlled via chart_settings(x, hole_size = ...). Data must be pre-aggregated with one row per slice and no grouping column. ```APIDOC ## ms_piechart(data, x, y, labels = NULL) ### Description Creates a piechart object that can be inserted into a Microsoft document. Pie charts show the proportion of each category as a slice of a circle; doughnut charts are similar but have a hole in the centre, controlled via chart_settings(x, hole_size = ...). Data must be pre-aggregated with one row per slice and no grouping column. ### Usage ```r ms_piechart(data, x, y, labels = NULL) ``` ### Arguments - **data** (data.frame) - Required - A data.frame. - **x** (column name) - Required - Column name for categories (slices). - **y** (column name) - Required - Column name for values (slice sizes). - **labels** (column names) - Optional - Column names of columns to be used as custom data labels displayed next to data points (not axis labels). If more than one name is provided, only the first one will be used as a label, but all labels (transposed if a group is used) will be available in the Excel file associated with the chart. ### Value An `ms_chart` object. ### Example ```r library(officer) library(mschart) dat <- data.frame( browser = c("Chrome", "Firefox", "Safari", "Edge", "Other"), value = c(64, 12, 8, 5, 11) ) # Pie chart pie <- ms_piechart(data = dat, x = "browser", y = "value") pie <- chart_labels(pie, title = "Browser share") # Doughnut chart donut <- ms_piechart(data = dat, x = "browser", y = "value") donut <- chart_settings(donut, hole_size = 50) donut <- chart_labels(donut, title = "Browser share (donut)") ``` ``` -------------------------------- ### Create and add a bar chart to a PowerPoint slide Source: https://github.com/ardata-fr/mschart/blob/main/man/ph_with.ms_chart.Rd Builds a clustered vertical bar chart from browser_data, configures axes and gap width, then adds it to a new 'Title and Content' slide using ph_with() with ph_location_fullsize(). Requires the officer package. The result is saved to a temporary .pptx file. ```R my_barchart <- ms_barchart(data = browser_data, x = "browser", y = "value", group = "serie") my_barchart <- chart_settings( x = my_barchart, dir="vertical", grouping="clustered", gap_width = 50 ) my_barchart <- chart_ax_x( x= my_barchart, cross_between = 'between', major_tick_mark="out") my_barchart <- chart_ax_y( x= my_barchart, cross_between = "midCat", major_tick_mark="in") library(officer) doc <- read_pptx() doc <- add_slide(doc, "Title and Content", "Office Theme") doc <- ph_with(doc, my_barchart, location = ph_location_fullsize()) fileout <- tempfile(fileext = ".pptx") print(doc, target = fileout) ``` -------------------------------- ### Create a bubble chart with ms_bubblechart Source: https://github.com/ardata-fr/mschart/blob/main/man/ms_bubblechart.Rd Builds an ms_chart bubble chart from a data.frame with x, y, size, and optional group columns. Adjust axes with chart_ax_x and chart_ax_y to avoid clipping extreme bubbles. ```R library(officer) dat <- data.frame( x = c(1, 2, 3, 4, 5), y = c(10, 20, 15, 25, 30), sz = c(5, 10, 7, 15, 12), grp = rep("s1", 5) ) bubble <- ms_bubblechart( data = dat, x = "x", y = "y", size = "sz", group = "grp" ) # adjust axes to avoid clipping extreme bubbles bubble <- chart_ax_x(bubble, limit_min = 0, limit_max = 6) bubble <- chart_ax_y(bubble, limit_min = 5, limit_max = 35) bubble ``` -------------------------------- ### Apply chart_settings to ms_areachart Source: https://github.com/ardata-fr/mschart/blob/main/man/chart_settings.Rd Creates an area chart and applies chart_settings with grouping='percentStacked'. ```R chart_03 <- ms_areachart( data = browser_ts, x = "date", y = "freq", group = "browser" ) chart_03 <- chart_settings(chart_03, grouping = "percentStacked" ) ```