jpcompartir / DisplayR

https://jpcompartir.github.io/DisplayR/
Other
0 stars 2 forks source link

Mosaic plots #29

Open jpcompartir opened 6 months ago

jpcompartir commented 6 months ago

For displaying x in y and y in x Useful for two categorical variables Functionality for adding raw values + % to bars of a certain size/value Guidance for highlighting specific values of x or y

Probably using ggmosaic but if other more suitable add-ons (and best if no added deps!) then no probs

jpcompartir commented 4 months ago

A very basic implementation would look like this

` library(ggmosaic) library(ggplot2) mosaic_plot <- function(data, x_var, y_var){

x_sym <- rlang::ensym(x_var) y_sym <- rlang::ensym(y_var)

plot <- data %>% ggplot2::ggplot() + ggmosaic::geom_mosaic(aes(x = ggmosaic::product(!!x_sym), fill = !!y_sym)) + dr_theme_capture() + theme(panel.grid = element_blank())

return(plot) }`