Creation of a piechart object that can be inserted in 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. Use chart_settings(x, hole_size = ...) to
control the hole size: 0 produces a pie chart, values
above 0 produce a doughnut chart.
Data must be pre-aggregated: one row per slice, no grouping column.
Arguments
- data
a data.frame
- x
column name for categories (slices).
- y
column name for values (slice sizes).
- labels
column names of columns to be used as custom data labels displayed next to data points (not axis labels). Optional. 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.
See also
chart_settings(), chart_data_labels(), chart_theme(), chart_labels()
Other 'Office' chart objects:
ms_areachart(),
ms_barchart(),
ms_boxplotchart(),
ms_bubblechart(),
ms_chart_combine(),
ms_funnelchart(),
ms_histogramchart(),
ms_linechart(),
ms_paretochart(),
ms_radarchart(),
ms_scatterchart(),
ms_stockchart(),
ms_sunburstchart(),
ms_treemapchart(),
ms_waterfallchart()
Examples
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)")
