Visualize Distribution with Automatically Calculated Quantile Highlights
coloured_histogram_quantiles.Rd
This function creates a histogram for a specified column in a dataframe,
highlighting quantiles that are automatically calculated based on the number
of quantiles specified by the user. It draws vertical lines for each quantile
in specified colors, with the title of the plot incorporating the capitalized
column name using tools::toTitleCase()
.
Arguments
- df
Dataframe containing the data to be visualized.
- col_name
Name of the column to create a histogram for. This column should contain numeric data.
- n_quantiles
The number of quantiles to calculate. If n_quantiles is 4, this will produce quartiles; if 5, quintiles; etc. This should be a positive integer greater than 1.
- binwidth
Width of the bins for the histogram. Can be adjusted for finer or coarser resolution of the distribution. Default is 1.
Value
A ggplot object representing the histogram with highlighted quantiles. The plot can be printed or modified further.
Examples
if (FALSE) {
# `df_nz` is the included dataframe with a numeric column 'forgiveness':
df_19 <- dplyr::filter(df_nz, wave == 2019)
quantile_plot <- coloured_histogram_quantiles(
df = df_19,
col_name = "forgiveness",
n_quantiles = 4, # producing quartiles
binwidth = 0.5 # adjust binwidth as needed
)
}
print(quantile_plot)
#> Error in eval(expr, envir, enclos): object 'quantile_plot' not found