Skip to content

Feature request: multiple grouping variables #279

Open
@okenk

Description

@okenk

Hi, thanks so much for the package, it's a huge help! I am cross-posting this issue on the stan forums in case there is a solution I am missing. Essentially I am trying to visualize the posterior predictive distributions across two grouping variables instead of one. I am using bayesplot::ppc_violin_grouped() which is working like a charm for the first grouping variable, but then I'd like to facet by the second grouping variable.

I thought I might be able to just add this to an existing plot using facet_wrap(). I looked at the data component of the bayesplot object and first tried to emulate that. However, I got an error that the length was wrong. If I then change the length of the facet variable to what the error asks for, it then wants a different length. Minimally reproducible example:

mod <- brms::brm(mpg ~ cyl + gear, data = mtcars, iter = 200)
ppc <- brms::posterior_predict(mod)
base.plot <- bayesplot::ppc_violin_grouped(y = mtcars$mpg, yrep = ppc, group = mtcars$gear) 

# try to replicate structure of base.plot$data
base.plot +
  facet_wrap(~c(rep(mtcars$cyl, each = 400), mtcars$cyl))

# change based on resulting error
base.plot +
  facet_wrap(~rep(mtcars$cyl, each = 400))

# change based on resulting error
base.plot +
  facet_wrap(~mtcars$cyl)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions