categorical_col_chart {SangerTools} | R Documentation |
Plot Counts of Categorical Variables
Description
Create a ggplot2 column chart of categorical variables with labels, in ascending order.
The plot will be customised using the provided theme theme_sanger
, y-axis labels will have a comma for every third integer value.
If the column provided to 'grouping_var' has more than approximately 5 values, you may need to consider
rotating x axis labels using theme
A comprehensive explanation of ggplot2 customisation is available here
Usage
categorical_col_chart(df, grouping_var)
Arguments
df |
A dataframe with categorical variables |
grouping_var |
a categorical variable by which to group the count by |
Value
a ggplot2 object
Examples
library(SangerTools)
library(dplyr)
library(ggplot2)
# Group by Age Band
health_data <- SangerTools::PopHealthData
health_data %>%
dplyr::filter(Smoker == 1) %>%
SangerTools::categorical_col_chart(AgeBand) +
labs(
title = "Smoking Population by Age Band",
subtitle = "Majority of Smokers are Working Aged ",
x = NULL,
y = "Patient Number"
)
[Package SangerTools version 1.0.2 Index]