Skip to contents

Enable native leader lines for a chart's data labels and, optionally, style the connecting line. Leader lines join a data label to its data point and are especially useful on pie and doughnut charts when labels are pushed outside the slices (position = "outEnd").

The original mschart could not turn these on (see the "Sorry, no" response on ardata-fr/mschart issue #69); this exposes the native c:showLeaderLines / c:leaderLines chart elements.

Usage

chart_labels_leaders(x, show = TRUE, line = NULL)

Arguments

x

an ms_chart object.

show

logical(1): whether to display leader lines. Default TRUE.

line

an officer::fp_border() describing the leader-line stroke (colour, width, style). Optional; when omitted Office uses its default leader-line style.

Value

An ms_chart object.

Details

Leader lines are honoured by Office primarily on pie and doughnut charts. They are emitted into the group data-label settings, so call chart_data_labels() first (for example to show values and move them outEnd) and then chart_labels_leaders().

Examples

library(officer)

pie_data <- data.frame(
  segment = c("Alpha", "Beta", "Gamma", "Delta"),
  share = c(30, 25, 20, 25),
  stringsAsFactors = FALSE
)
pie <- ms_piechart(data = pie_data, x = "segment", y = "share")
pie <- chart_data_labels(pie, show_percent = TRUE, position = "outEnd")
pie <- chart_labels_leaders(pie, line = fp_border(color = "gray50", width = 1))

doc <- read_pptx()
doc <- add_slide(doc, "Title and Content", "Office Theme")
doc <- ph_with(doc, pie, location = ph_location_fullsize())
print(doc, target = tempfile(fileext = ".pptx"))