categorical_var_summary_by_segments: Create a summary of a categorical variable segmented by...

Description Usage Arguments See Also Examples

Description

This function creates a bar plot by one discrete/factor/charactor variable, calculates the number of levels within this variable, plots it on the y-axis. Then, it looks at the other categorical variable and calculates counts and percentage of its levels with respect to the first factor variable. Therefore, creating first categorical segments by the second categorical levels.

Usage

1
2
3
4
5
6
7
categorical_var_summary_by_segments(df, categorical_col_y,
  categorical_col_x, get_group_counts = FALSE,
  guide_legend_reverse = TRUE, plot_labs = list(title =
  paste(rlang::quo_name(rlang::enquo(categorical_col_y)), "by",
  paste(rlang::quo_name(rlang::enquo(categorical_col_x)),
  " Distribution")), subtitle = paste("Total sample size = ", nrow(df)),
  fill = NULL), custom_colour_pallet = NULL)

Arguments

df

a dataframe/tibble

categorical_col_y

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

categorical_col_x

factor/character variable used to calculate segments of the categorical_col_y

get_group_counts

if TRUE, then returns a tibble/data frame of categorical_col_y with counts and proportions of the categorical_col_x

guide_legend_reverse

if plot legend needs to be in reversed order

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")

See Also

theme

Examples

1
2
3
4
5
6
## Not run: 
categorical_var_summary_by_segments(mtcars,cyl,gear)
plot_labs <-  list(title = "Overall Cyl Distribution in mtcars segmented by gear",fill = NULL)
categorical_var_summary_by_segments(mtcars,cyl,gear,plot_labs ,get_group_counts = TRUE)

## End(Not run)

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