mschart (version 0.2.4)

as_bar_stack: set a barchart as a stacked barchart

Description

Apply 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

as_bar_stack(x, dir = "vertical", percent = FALSE, gap_width = 50)

Arguments

x

an ms_barchart object

dir

the direction of the bars in the chart, value must one of "horizontal" or "vertical".

percent

should bars be in percent

gap_width

gap width between the bar for each category on a bar chart, in percent of the bar width. It can be set between 0 and 500.

Examples

Run this code
# NOT RUN {
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_chart(doc, chart = my_bar_stack_02)

fileout <- tempfile(fileext = ".pptx")
print(doc, target = fileout)
# }

Run the code above in your browser using DataCamp Workspace