View source: R/categorical_col_chart.R
categorical_col_chart | R Documentation |
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
categorical_col_chart(df, grouping_var)
df |
A dataframe with categorical variables |
grouping_var |
a categorical variable by which to group the count by |
a ggplot2 object
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" )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.