chart_hc_imd_bar: Highcharts bar plot for values split by IMD decile

View source: R/chart_hc_imd_bar.R

chart_hc_imd_barR Documentation

Highcharts bar plot for values split by IMD decile

Description

Visualisation creation function: Create highchart object showing bar plot IMD decile distribution.

The chart will be a highchart object for a single series chart with a bar per IMD decile. The parameters supplied will allow basic formatting to be applied to the chart object.

Some chart elements (e.g. title, caption) have been excluded from the function although this can be added to the highcharts object returned from this function.

Usage

chart_hc_imd_bar(
  df,
  imd_col,
  value_col,
  metric_def,
  highlight_core20 = FALSE,
  show_lbl = FALSE,
  value_dp = 0,
  value_prefix = "",
  order_of_magnitude = ""
)

Arguments

df

A data frame containing data to plot

imd_col

String defining name of column within the data that holds the IMD classification (values should be 1 to 10)

value_col

String defining name of column within the data that holds the values to be plotted

metric_def

String for the metric being reported (will be used as y-axis title and in tooltip)

highlight_core20

Should Core20 be highlighted

  • Default = TRUE

  • TRUE:- the Core20 deciles (IMD = 1 or 2) will be highlighted within the output

  • FALSE:- no emphasis will be applied to highlight any of the deciles

show_lbl

Should data labels be shown

  • Default = TRUE

  • TRUE:- data labels will be included above each decile bar

  • FALSE:- no data labels will be included in the output (values will still be in tooltip)

value_dp

No. of decimal places to format values to

  • Default = 0

  • Only values between 0 and 3 are valid

  • Decimal values beyond 3 points are not easy to digest and alternative reporting should be considered

value_prefix

Any value prefix that should be displayed

  • Default = ""

  • Prefix will be included in the axis title and prior to data values (e.g. £1)

order_of_magnitude

Character to identify if figures should be adjusted to specific abbreviation

  • Default = ""

  • k:- values will be divided by 1,000 and figures will include "k" suffix

  • m:- values will be divided by 1,000,000 and figures will include "m" suffix

  • bn:- values will be divided by 1,000,000,000 and figures will include "bn" suffix

  • tn:- values will be divided by 1,000,000,000,000 and figures will include "tn" suffix

Value

Highchart object for bar chart showing data by IMD decile

Examples

# Example code for chart_hc_imd_bar

# create the test data frame
df_imd_data <- data.frame(
  IMD = c(1,2,3,4,5,6,7,8,9,10),
  VALUE = sample(100000:200000, size = 10 , replace = TRUE)
)

# create chart object
chart_hc_imd_bar(
  df = df_imd_data,
  imd_col = "IMD",
  value_col = "VALUE",
  metric_def = "Example cost values",
  highlight_core20 = TRUE,
  show_lbl = FALSE,
  value_dp = 1,
  value_prefix = "£",
  order_of_magnitude = "k"
)

nhsbsa-data-analytics/nhsbsaR documentation built on Jan. 25, 2025, 8:54 a.m.