grouped_barchart.Rd
This function generates a grouped bar chart using ggplot2, where bars are grouped by a specified variable.
grouped_barchart(data, xvar, yvar, groupvar, chartcolors)
A data frame containing at least 3 variables: x-axis variable, y-axis variable, and a grouping variable.
A string specifying the name of the variable to be plotted on the x-axis.
A string specifying the name of the variable to be plotted on the y-axis.
A string specifying the name of the grouping variable.
A vector of colors with the same length as the number of levels in the grouping variable.
A ggplot object representing the grouped bar chart.
The function creates a bar chart where bars are grouped based on the specified grouping variable. It uses position = "dodge" to place bars side by side within each group. The y-axis line, minor grid lines, and y-axis ticks are removed for a cleaner appearance.
This function requires the ggplot2 package and assumes the existence of a custom theme function br_charts_theme().
# Assuming 'comorbidities' is a data frame with appropriate columns
# and 'colfun()$fig4_colors' returns a vector of colors
grouped_barchart(
data = comorbidities,
xvar = "Comorbidities",
yvar = "Prevalence",
groupvar = "Severity",
chartcolors = colfun()$fig4_colors
)