ProjectMOSAIC / ggformula

Provides a formula interface to 'ggplot2' graphics.
Other
38 stars 11 forks source link

Allow users to control "denominators" used in gf_props() #139

Closed rpruim closed 2 years ago

rpruim commented 4 years ago

This supersedes #112, I think.

Ideas:

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)")

Created on 2020-07-04 by the reprex package (v0.3.0)

rpruim commented 4 years ago

To do:

rpruim commented 3 years ago

@dtkaplan and @nicholasjhorton : Have either of you used this feature? Any comments?

nicholasjhorton commented 3 years ago

I've not used this feature.