Skip to contents

Producing a Pie Chart

Usage

plotPieChart(
  data = NULL,
  metaData = NULL,
  dataMapping = NULL,
  colorPalette = NULL,
  start = NULL,
  clockwiseDirection = NULL,
  plotConfiguration = NULL,
  plotObject = NULL
)

Arguments

data

A data.frame to use for plot.

metaData

A named list of information about data such as the dimension and unit of its variables.

dataMapping

A PieChartDataMapping object mapping x and fill aesthetic groups to their variable names of data. Values mapped to y variable will be displayed as text within the pie chart

colorPalette

color palette property from ggplot2

start

Offset of starting point from 12 o'clock in radians. Offset is applied clockwise or anticlockwise depending on value of direction

clockwiseDirection

logical defining if values are displayed in clockwise order

plotConfiguration

An optional PieChartPlotConfiguration object defining labels, grid, background and watermark.

plotObject

An optional ggplot object on which to add the plot layer

Value

A ggplot object

Examples

# Data for the pie chart
values <- runif(5)
data <- data.frame(
  values = values,
  text = paste0(round(100 * values / sum(values)), "%"),
  legend = letters[1:5]
)

# Plot pie chart with its legend
plotPieChart(
  data = data,
  dataMapping = PieChartDataMapping$new(x = "values", fill = "legend")
)


# Plot pie chart with text within pie
plotPieChart(
  data = data,
  dataMapping = PieChartDataMapping$new(x = "values", y = "text", fill = "legend")
)


# Reverse direction of pie chart
plotPieChart(
  data = data,
  dataMapping = PieChartDataMapping$new(x = "values", y = "text", fill = "legend"),
  clockwiseDirection = FALSE
)


# Start first slice of pie at 90 degrees
plotPieChart(
  data = data,
  dataMapping = PieChartDataMapping$new(x = "values", y = "text", fill = "legend"),
  start = pi / 2
)


# Leverages ggplot color palettes
plotPieChart(
  data = data,
  dataMapping = PieChartDataMapping$new(x = "values", y = "text", fill = "legend"),
  colorPalette = ColorPalettes$Set1
)