Description Usage Arguments Value Examples
The function uses a data set and a variable (or two variables) to generate a ggplot with proportions. It uses the "original" data set, i.e., it assumes that no prior 'count' or aggregations were performed. It detects if the data has a prior grouping variable. If a 'group_by' of one variable is detected, the function will use the grouping variable on the x-axis and the input variable as the fill aesthetics. If no prior grouping variable is detected, the function will use the input variable as the x-axis and the proportions of values as y-axis. The function fails if a more than one variable grouping is detected.
1 2 3 4 5 6 7 8 9 |
data |
The data set |
vari |
The variable on which proportions are calculated |
title |
The plot's title |
subtitle |
The plot's subtitle |
caption |
The plot's caption |
arrange_desc |
Should the plot arrange the bars in descending order (relative to proportions) |
add_labels |
Should labels be added on the bars (geom_label is used) |
A ggplot2 object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | data <-
tibble(fruit =
c("apple", "orange", "orange", "paer", "mango", "mango", "mango"),
gender =
c("M", "M", "F", "F", "M", "F", "F"),
favorite_color =
c("Blue", "Red", "Green", "Blue", "Red", "Green", "Blue")
)
data %>%
gg_prop_plot(fruit)
data %>%
gg_prop_plot(fruit, arrange_desc = F)
data %>%
group_by(gender) %>%
gg_prop_plot(fruit)
data %>%
group_by(favorite_color, gender) %>%
gg_prop_plot(fruit)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.