Package 'controlcharts'

Title: Interactive Plotting for Funnel and Statistical Process Control Charts
Description: Generate fully interactive and dynamic funnel plots and statistical process control (SPC) charts. All data manipulation, calculation, and plotting is done in JavaScript, allowing for completely dynamic charts without the need for a Shiny server.
Authors: Andrew R. Johnson [aut, cre] (ORCID: <https://orcid.org/0000-0001-7000-8065>), Healthcare Quality Intelligence Unit (Western Australia Health) [aut]
Maintainer: Andrew R. Johnson <[email protected]>
License: MIT + file LICENSE
Version: 0.0.13
Built: 2026-06-08 05:32:37 UTC
Source: https://github.com/AUS-DOH-Safety-and-Quality/controlcharts

Help Index


Generate interactive Funnel chart

Description

Generate interactive Funnel chart

Usage

funnel(
  data,
  keys,
  numerators,
  denominators,
  tooltips,
  labels,
  aggregations = list(numerators = "sum", denominators = "sum", tooltips = "first",
    labels = "first"),
  title = NULL,
  canvas_settings = NULL,
  funnel_settings = NULL,
  outlier_settings = NULL,
  scatter_settings = NULL,
  line_settings = NULL,
  x_axis_settings = NULL,
  y_axis_settings = NULL,
  label_settings = NULL,
  tooltip_settings = NULL,
  width = NULL,
  height = NULL,
  elementId = NULL,
  return_objs = c("html_plot", "static_plot", "limits")
)

Arguments

data

A data frame containing the data for the chart.

keys

A vector or column name representing the categories of the chart.

numerators

A numeric vector or column name representing the numerators for each category.

denominators

A numeric vector or column name representing the denominators for each category.

tooltips

A vector or column name representing the tooltips for each category.

labels

A vector or column name representing the labels for each category.

aggregations

A list of aggregation function names for each field if multiple values are provided for each key. Valid options are:

  • "first": returns the first value

  • "last": returns the last value

  • "sum": returns the sum of values

  • "mean": returns the mean of values

  • "min": returns the minimum value

  • "max": returns the maximum value

  • "median": returns the median value

  • "count": returns the count of values

title

Optional title to be added to the top of the chart. It can be a character string for the title text only, or a list with the following options:

  • text: Title text (default: NULL)

  • font_size: Font size of the title (default: "16px")

  • font_weight: Font weight of the title (default: "bold")

  • font_family: Font family of the title (default: "'Arial', sans-serif")

  • x: Horizontal (x) position of the title as a percentage (default: "50%")

  • y: Vertical (y) position of the title in pixels (default: 5)

  • text_anchor: Text anchor of the title (default: "middle")

  • dominant_baseline: Dominant baseline of the title (default: "hanging")

canvas_settings

Optional list of settings for the canvas, see funnel_default_settings('canvas') for valid options.

funnel_settings

Optional list of settings for the Funnel chart, see funnel_default_settings("funnel") for valid options.

outlier_settings

Optional list of settings for outliers, see funnel_default_settings('outliers') for valid options.

scatter_settings

Optional list of settings for scatter points, see funnel_default_settings('scatter') for valid options.

line_settings

Optional list of settings for lines, see funnel_default_settings('lines') for valid options.

x_axis_settings

Optional list of settings for the x-axis, see funnel_default_settings('x_axis') for valid options.

y_axis_settings

Optional list of settings for the y-axis, see funnel_default_settings('y_axis') for valid options.

label_settings

Optional list of settings for labels, see funnel_default_settings('labels') for valid options.

tooltip_settings

Optional list of settings for tooltips, see funnel_default_settings('tooltips') for valid options.

width

Optional width of the chart in pixels. If NULL (default), the chart will fill the width of its container.

height

Optional height of the chart in pixels. If NULL (default), the chart will fill the height of its container.

elementId

Optional HTML element ID for the chart.

return_objs

Character vector of object types to return. Valid values are:

  • "html_plot": Interactive htmlwidgets plot

  • "static_plot": Non-interactive SVG plot

  • "limits": Calculated control limits

Value

An object of class controlchart containing the interactive plot, static plot, limits data frame, raw data, and a function to save the plot.


Get default settings for Funnel charts Retrieve the default settings for Funnel charts or a specific settings group.

Description

Get default settings for Funnel charts Retrieve the default settings for Funnel charts or a specific settings group.

Usage

funnel_default_settings(group = NULL)

Arguments

group

Optional. A specific settings group to retrieve. If NULL, all settings groups are returned.

Value

A list of default settings for Funnel charts or the specified settings group.

Examples

#' # Get all default settings for Funnel charts
funnel_default_settings()
# # Get default settings for a specific group
funnel_default_settings("x_axis")

Shiny bindings for wrapper

Description

Output and render functions for using wrapper within Shiny applications and interactive Rmd documents.

Usage

funnelOutput(outputId, width = "100%", height = "400px")

renderfunnel(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width, height

Must be a valid CSS unit (like '100%', '400px', 'auto') or a number, which will be coerced to a string and have 'px' appended.

expr

An expression that generates a wrapper

env

The environment in which to evaluate expr.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.


Generate interactive SPC chart

Description

Generate interactive SPC chart

Usage

spc(
  data,
  keys,
  numerators,
  denominators,
  groupings,
  xbar_sds,
  tooltips,
  labels,
  aggregations = list(numerators = "sum", denominators = "sum", groupings = "first",
    xbar_sds = "first", tooltips = "first", labels = "first"),
  title = NULL,
  canvas_settings = NULL,
  spc_settings = NULL,
  outlier_settings = NULL,
  nhs_icon_settings = NULL,
  scatter_settings = NULL,
  line_settings = NULL,
  x_axis_settings = NULL,
  y_axis_settings = NULL,
  date_settings = NULL,
  label_settings = NULL,
  tooltip_settings = NULL,
  width = NULL,
  height = NULL,
  elementId = NULL,
  return_objs = c("html_plot", "static_plot", "limits")
)

Arguments

data

A data frame containing the data for the chart.

keys

A vector or column name representing the categories (x-axis) of the chart.

numerators

A numeric vector or column name representing the numerators for each category.

denominators

A numeric vector or column name representing the denominators for each category.

groupings

A vector or column name representing the grouping for each category.

xbar_sds

A numeric vector or column name representing the x-bar and standard deviation values for each category.

tooltips

A vector or column name representing the tooltips for each category.

labels

A vector or column name representing the labels for each category.

aggregations

A list of aggregation function names for each field if multiple values are provided for each key. Valid options are:

  • "first": returns the first value

  • "last": returns the last value

  • "sum": returns the sum of values

  • "mean": returns the mean of values

  • "min": returns the minimum value

  • "max": returns the maximum value

  • "median": returns the median value

  • "count": returns the count of values

title

Optional title to be added to the top of the chart. It can be a character string for the title text only, or a list with the following options:

  • text: Title text (default: NULL)

  • font_size: Font size of the title (default: "16px")

  • font_weight: Font weight of the title (default: "bold")

  • font_family: Font family of the title (default: "'Arial', sans-serif")

  • x: Horizontal (x) position of the title as a percentage (default: "50%")

  • y: Vertical (y) position of the title in pixels (default: 5)

  • text_anchor: Text anchor of the title (default: "middle")

  • dominant_baseline: Dominant baseline of the title (default: "hanging")

canvas_settings

Optional list of settings for the canvas, see spc_default_settings('canvas') for valid options.

spc_settings

Optional list of settings for the SPC chart, see spc_default_settings('spc') for valid options.

outlier_settings

Optional list of settings for outliers, see spc_default_settings('outliers') for valid options.

nhs_icon_settings

Optional list of settings for NHS icons, see spc_default_settings('nhs_icons') for valid options.

scatter_settings

Optional list of settings for scatter points, see spc_default_settings('scatter') for valid options.

line_settings

Optional list of settings for lines, see spc_default_settings('lines') for valid options.

x_axis_settings

Optional list of settings for the x-axis, see spc_default_settings('x_axis') for valid options.

y_axis_settings

Optional list of settings for the y-axis, see spc_default_settings('y_axis') for valid options.

date_settings

Optional list of settings for dates, see spc_default_settings('dates') for valid options.

label_settings

Optional list of settings for labels, see spc_default_settings('labels') for valid options.

tooltip_settings

Optional list of settings for tooltips, see spc_default_settings('tooltips') for valid options.

width

Optional width of the chart in pixels. If NULL (default), the chart will fill the width of its container.

height

Optional height of the chart in pixels. If NULL (default), the chart will fill the height of its container.

elementId

Optional HTML element ID for the chart.

return_objs

Character vector of object types to return. Valid values are:

  • "html_plot": Interactive htmlwidgets plot

  • "static_plot": Non-interactive SVG plot

  • "limits": Calculated control limits

Value

An object of class controlchart containing the interactive plot, static plot, limits data frame, and a function to save the plot.


Get default settings for SPC charts

Description

Retrieve the default settings for SPC charts or a specific settings group.

Usage

spc_default_settings(group = NULL)

Arguments

group

Optional. A specific settings group to retrieve. If NULL, all settings groups are returned.

Value

A list of default settings for SPC charts or the specified settings group.

Examples

#' # Get all default settings for SPC charts
spc_default_settings()
# # Get default settings for a specific group
spc_default_settings("x_axis")

Shiny bindings for wrapper

Description

Output and render functions for using wrapper within Shiny applications and interactive Rmd documents.

Usage

spcOutput(outputId, width = "100%", height = "400px")

renderSpc(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width, height

Must be a valid CSS unit (like '100%', '400px', 'auto') or a number, which will be coerced to a string and have 'px' appended.

expr

An expression that generates a wrapper

env

The environment in which to evaluate expr.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.