mk_barploth_resp: Create a function for making ggplot2 horizontal bar charts,...

View source: R/mk_barploth_resp.R

mk_barploth_respR Documentation

Create a function for making ggplot2 horizontal bar charts, showing the sums of a continuous variable by 1 or 2 categorical variables.

Description

mk_barploth_resp takes a data frame as input and returns a function for making bar charts with any categorical variable from the data frame on the y-axis and the sums of any continuous variable on the x-axis. The output function can also produce dodged bar charts when supplied a second categorical variable. The resulting bar chart will have bars ordered by the alphanumerical order of the y levels by default, and labeled by the sums of the x values. Users can specify the number of decimal places to show on the bar labels. If the sums of x values are between 0 and 1, users can choose to format the x-axis and the bar labels as percent ( clean theme and font, and uses color-blind friendly palettes.

Usage

mk_barploth_resp(df)

Arguments

df

A data frame.

Value

function(xvar, yvar, fillby = "1", yorder = "alphanumeric", show_pct = FALSE, label_decimals = 1, label_size = 4, legend_title = fillby, legend_pos = "right", font_size = 14)

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

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

  • fillby String. Name of a different categorical variable for subdividing and coloring the bars. Default = "1", meaning no such variable is supplied.

  • yorder String. Possible values: "alphanumeric" (default), "ascend" or "descend". It specifies how categories are ordered on the y-axis.

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

  • label_decimals Integer. The number of decimal places shown on the bar labels. Default = 1.

  • label_size Integer. The size of bar label text. Default = 4. If 0, bar labels will not be shown.

  • legend_title String. Legend title. Default is the name of the 'fillby' variable.

  • legend_pos String. Legend position. Possible values are "right" (default), 'left', 'top' and 'bottom'.

  • font_size Number. Overall font size (default = 14). The font size of the axes and legend is a fraction of this value.

See Also

get_bar_labels_resp for how to calculate the positions of the bar labels.

Examples

inst/examples/ex-mk_barploth_resp.R

cabaceo/shinymod documentation built on Sept. 8, 2023, 12:23 p.m.