mk_lollipop: Create a function for making publishable ggplot2 horizontal...

View source: R/mk_lollipop.R

mk_lollipopR Documentation

Create a function for making publishable ggplot2 horizontal lollipop charts, showing single or cumulative values of a continuous variable by a categorical variable.

Description

mk_lollipop takes a data frame as input and returns a function for making horizontal lollipop charts with any categorical variable from the data frame on y-axis and the value (or cumulative values) of any continuous variable on x-axis. The resulting chart will have the y levels ordered alphanumerically by default. It'll label the stems of lollipops with the cumulative x values. If the x values are decimals, user can specify the number of decimals to display. If the x values are between 0 and 1, user can choose to format the x-axis and the labels as percent ( the resulting plot will have a clean theme and clear fonts. It'll also use color-blind friendly palettes.

Usage

mk_lollipop(df)

Arguments

df

A data frame.

Value

function(xvar, yvar, yorder = "alphanumeric", show_pct = FALSE, label_decimals = 1, label_size = 3, font_size = 14)

  • xvar. String, name of a continuous variable for x-axis.

  • yvar. String, name of a categorical variable for y-axis.

  • yorder. String, "alphanumeric", "ascend" or "descend". It specifies how categories are ordered on the y-axis. Default = "alphanumeric".

  • show_pct. Logical, if TRUE, format x-axis and bar labels as otherwise, format them as comma. Default is FALSE.

  • label_decimals. Integer, the number of decimal points shown on the bar labels. Default = 1.

  • label_size. Integer, size of bar label text. Default = 3. Hide bar labels when its value is 0.

  • font_size. Overall font size. Default = 14. The font size of the axes and legend text is a fraction of this value.

See Also

scale_axis for adding different scales to the y-axis.

Examples

inst/examples/ex-mk_lollipop.R

gmlang/ezplot documentation built on Sept. 18, 2022, 6:33 a.m.