Intro Thoughts

Status Quo

Experiment

library(tidyverse)


ggtable <- function(data){
  
  ggplot(data) + 
    aes(x = "All", y = "All") + 
    geom_count() ->>
  p
  
  layer_data(p)
  
}


set_cols <- function(pipe_spacer, cols){
  
  p + 
    aes(x = {{cols}}) ->>
  p

  # x_values_df <- layer_data(p, i = 1) %>%  .[,c("x", "group")] |> distinct()
  # x_var_name <- p$mapping$x |> capture.output() %>% .[2] %>% str_extract("\\^.+") %>% str_remove("\\^")
  # x_var_df <- p$data[x_var_name] %>% distinct()
  # names(x_var_df) <- "x_var"
  # x_var_df <- mutate(x_var_df, group = as.numeric(x_var))
  # x_numeric_cat_crosswalk <- left_join(x_values_df, x_var_df, by = join_by(group))
  # 
  # 
  # y_values_df <- layer_data(p, i = 1) %>%  .[,c("y", "group")] |> distinct()
  # y_var_name <- p$mapping$y |> capture.output() %>% .[2] %>% str_extract("\\^.+") %>% str_remove("\\^")
  # y_var_df <- p$data[y_var_name] %>% distinct()
  # names(y_var_df) <- "y_var"
  # y_var_df <- mutate(y_var_df, group = as.numeric(y_var))
  # y_numeric_cat_crosswalk <- left_join(y_values_df, y_var_df, by = join_by(group))
  
  # print(p)
   layer_data(p) %>% 
    #  mutate(x = factor(x, 
    #                    levels = x_numeric_cat_crosswalk$group, 
    #                    labels = x_numeric_cat_crosswalk$x_var)) %>% 
    # mutate(y = factor(y,  
    #                   levels = y_numeric_cat_crosswalk$group, 
    #                   labels = y_numeric_cat_crosswalk$y_var)) %>% 
     select(x, y, n) %>% 
     pivot_wider(names_from = x, values_from = n)
  
}

set_rows <- function(pipe_spacer, rows){
  
  p + 
    aes(y = {{rows}}) ->>
  p
  
  # x_values_df <- layer_data(p, i = 1) %>%  .[,c("x", "group")] |> distinct()
  # x_var_name <- p$mapping$x |> capture.output() %>% .[2] %>% str_extract("\\^.+") %>% str_remove("\\^")
  # x_var_df <- p$data[x_var_name] %>% distinct()
  # names(x_var_df) <- "x_var"
  # x_var_df <- mutate(x_var_df, group = as.numeric(x_var))
  # x_numeric_cat_crosswalk <- left_join(x_values_df, x_var_df, by = join_by(group))
  # 
  # y_values_df <- layer_data(p, i = 1) %>%  .[,c("y", "group")] |> distinct()
  # y_var_name <- p$mapping$y |> capture.output() %>% .[2] %>% str_extract("\\^.+") %>% str_remove("\\^")
  # y_var_df <- p$data[y_var_name] %>% distinct()
  # names(y_var_df) <- "y_var"
  # y_var_df <- mutate(y_var_df, group = as.numeric(y_var))
  # y_numeric_cat_crosswalk <- left_join(y_values_df, y_var_df, by = join_by(group))
  
  layer_data(p) %>% 
    # mutate(x = factor(x,  
    #                   levels = x_numeric_cat_crosswalk$group, 
    #                   labels = x_numeric_cat_crosswalk$x_var)) %>% 
    # mutate(y = factor(y,  
    #                   levels = y_numeric_cat_crosswalk$group, 
    #                   labels = y_numeric_cat_crosswalk$y_var)) %>% 
    select(x, y, n) %>% 
    pivot_wider(names_from = x, values_from = n)
  
}


library(palmerpenguins)

ggtable(penguins) 
## Warning in geom_count(): All aesthetics have length 1, but the data has 344 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
##       size PANEL x y group   n prop shape colour fill alpha stroke
## 1 4.535534     1 1 1     1 344    1    19  black   NA    NA    0.5
  set_rows(species) 
## Warning in geom_count(): All aesthetics have length 1, but the data has 344 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## # A tibble: 1 × 2
##   y            `1`
##   <mppd_dsc> <dbl>
## 1 1            344
  set_cols(island)
## Warning in geom_count(): All aesthetics have length 1, but the data has 344 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## # A tibble: 1 × 2
##   y            `1`
##   <mppd_dsc> <dbl>
## 1 1            344

Closing remarks, Other Relevant Work, Caveats