categorical_var_summary: Create a summary of a categorical variable

Description Usage Arguments See Also Examples

Description

This function creates a bar plot by one discrete/factor/charactor variable, calculates the number of levels with counts and proportions of these levels with respect to the whole dataset and plots levels on the y-axis.

Usage

1
2
3
4
5
6
categorical_var_summary(df, categorical_col, get_table = F,
  plot_labs = list(title = paste("Overall",
  rlang::quo_name(rlang::enquo(group_var_y)), " Distribution"), subtitle =
  paste("Total sample size = ", nrow(df)), fill = NULL),
  custom_colour_pallet = NULL, guide_legend_reverse = F,
  data_ordered = TRUE)

Arguments

df

a dataframe/tibble

categorical_col

factor/character variable to be plotted on the y-axis

get_table

if TRUE, then returns a tibble/data frame of categorical_col with counts and proportions instead of a plot

plot_labs

pass as a list of plot labels such as x, y, title, subtitle etc.

custom_colour_pallet

pass as a vector of custom colour pallet. i.e. custom_colour_pallet = c("Promoter" = "#6400AA","Detractor" = "#E60050","Passive"="#00A0D6")

guide_legend_reverse

if plot legend needs to be in reversed order

data_ordered

Set to TRUE to order data for plotting

See Also

categorical_var_summary_by_segments

Examples

1
2
3
4
5
6
## Not run: 
categorical_var_summary(mtcars,cyl)
categorical_var_summary(mtcars,cyl,
                       custom_colour_pallet = c("8" = "#6400AA","4" = "#E60050","6"="#00A0D6"))

## End(Not run)

fahadshery/textsummary documentation built on May 6, 2019, 7:02 p.m.