ronkeizer / vpc

R library to create visual predictive checks (VPC)
Other
36 stars 20 forks source link

Bin settings for each STRAT group #38

Closed yoshidk6 closed 6 years ago

yoshidk6 commented 7 years ago

Quick workaround to assign different bin settings for each stratification group Each subplot is created individually with vpc function and combined with cowplot::plot_grid function.

Test code for two stratification variables

## Test dataset preparation
sim =
  simple_data$sim %>% tbl_df() %>% 
  mutate(STRAT1=ifelse(ID %% 2 == 1,"ODD","EVEN"),
         STRAT2=ifelse(ID<=16,"TOP","MIDDLE"),
         STRAT2=ifelse(ID> 32,"BOTTOM",STRAT2))
obs = 
  simple_data$obs %>% tbl_df() %>% 
  mutate(STRAT1=ifelse(ID %% 2 == 1,"ODD","EVEN"),
         STRAT2=ifelse(ID<=16,"TOP","MIDDLE"),
         STRAT2=ifelse(ID> 32,"BOTTOM",STRAT2))

## Run vpc_strat_bin
vpc_strat_bin(
  sim = sim,
  obs = obs,
  stratify = c("STRAT1","STRAT2"), 
  strat_fig_dir = 2,
  bin_list =
    list(c(0,0.4,0.75,1.25,1.75,2.25,2.75,3.5,5,7,10,13),
         c(0,    0.75,     1.75,     2.75,    5,  10,13),
         c(0,         1.25,          2.75,      7,   13),
         c(0,              1.75,              5,     13),
         c(0,         1.25,                     7,   13),
         c(0,                                 5,     13)),
  show = list(obs_dv = T),
  return_fig = T,
  facet_names = F
)

image

ronkeizer commented 7 years ago

hi, thanks for the pull request. I'll have a look a.s.a.p. I like the suggested added functionality, only thing i want to look at is if we can do this without the cowplot package, since we should aim to add as few dependencies as possible. Also, I wonder if we really need a new separate function to do this, perhaps we can integrate in the main vpc() functions?

yoshidk6 commented 6 years ago

Hi, I looked into this a bit more again but couldn't come up with a nice way to integrate without additional dependency. Will close it for now.