default to computing proportions separately in each panel
provide a denom argument that allows for other choices
Current WIP implementation uses ggplot2::after_stat() and so can determine the denominator based on anything computable from the statified data.
Here are some examples.
suppressPackageStartupMessages(library(mosaic))
theme_set(theme_bw())
T <- dplyr::bind_rows(
do(20) * tibble(a = "A", b = "E", c = "X"),
do(20) * tibble(a = "A", b = "E", c = "Z"),
do(10) * tibble(a = "A", b = "F", c = "X"),
do(10) * tibble(a = "A", b = "F", c = "Z"),
do(5) * tibble(a = "B", b = "E", c = "X"),
do(10) * tibble(a = "B", b = "E", c = "Z"),
do(15) * tibble(a = "B", b = "F", c = "X"),
do(10) * tibble(a = "B", b = "F", c = "Z"),
)
T %>% gf_props( ~ a | b ~ c, position = "dodge",
title = "proportions within panel")
T %>% gf_props( ~ a | b ~ c, fill = ~ b, position = "dodge", denom = ~ fill,
title = "proportions within fill")
T %>% gf_props( ~ a | b ~ c, fill = ~ c, position = "dodge", denom = ~ fill,
title = "proportions within fill")
T %>% gf_props( ~ a | b, fill = ~ c, position = "dodge", denom = ~ 1,
title = "proportions within all")
T %>% gf_props( ~ a | b ~ c, fill = ~ b, denom = ~ fill,
title = "proportions within fill")
T %>% gf_props( ~ a | b ~ c, fill = ~ c, group = ~b, denom = ~ fill,
title = "proportions within fill")
T %>% gf_props( ~ a | b ~ c, fill = ~ c, group = ~b, denom = ~ group,
title = "proportions in group (b = E or F)")
This supersedes #112, I think.
Ideas:
denom
argument that allows for other choicesCurrent WIP implementation uses
ggplot2::after_stat()
and so can determine the denominator based on anything computable from the statified data.Here are some examples.
Created on 2020-07-04 by the reprex package (v0.3.0)