Description Usage Arguments See Also Examples
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 summarises this variable's each level with a numeric variable by a given mathematical function. Also labels the numerical summary by each group.
1 2 3 4 5 6 7 8 | categorical_var_numeric_summary(df, categorical_col_y, num_var,
get_summary = F, plot_labs = list(title = paste("Summary of",
rlang::quo_name(rlang::enquo(categorical_col_y)), " by",
lazyeval::expr_text(FUN), rlang::quo_name(rlang::enquo(num_var))),
subtitle = paste("Total verbatim = ", nrow(df)), fill = NULL, y =
paste(lazyeval::expr_text(FUN), rlang::quo_name(rlang::enquo(num_var)))),
custom_colour_pallet = NULL, guide_legend_reverse = F,
data_ordered = TRUE, FUN = mean)
|
df |
a dataframe/tribble |
categorical_col_y |
factor/character variable to be plotted on the y-axis |
num_var |
numeric variable which will be used for mathematical summary |
get_summary |
if TRUE, then returns a tibble/data frame of categorical_col_y with mathematical summary by the num_var |
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 |
if the statiscal summary needs to be ordered |
FUN |
mathematical operation to be performed i.e. mean, median, sd, mode etc. |
categorical_var_summary_by_segments
1 2 3 4 5 6 7 | ## Not run:
categorical_var_numeric_summary(mtcars,cyl,mpg)
my_colours <- c("4" = "#6400AA","6" = "#E60050","8" = "black")
categorical_var_numeric_summary(mtcars, cyl,mpg,FUN = mean, custom_colour_pallet = my_colours)
categorical_var_numeric_summary(mtcars, cyl,mpg,FUN = sum, get_summary = TRUE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.