Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions for relabeling facets #170

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Functions for relabeling facets #170

wants to merge 5 commits into from

Conversation

jgabry
Copy link
Member

@jgabry jgabry commented Oct 23, 2018

@tjmahr I'm not sure this is the best way to offer this option, so if you have a better idea I'm definitely open to it. This PR adds functions facet_relabel_gg() and facet_vars(). These are intended to help users change facet labels. This is related to #75 and #157, although those issues relate mostly to changing legend labels, for which we will need some other option. This PR just addresses changing facet labels. (This wasn't much work so we can scrap it if it seems just like it's adding unnecessary bloat, since I suppose we could just tell people they need to use the factor labels they want used as facet labels and we won't provide a way to change them after the fact.)

Example

# example_group_data() has factor levels GroupA and GroupB which are used as facet labels
pgroup <- ppc_scatter_avg_grouped(y = example_y_data(), yrep = example_yrep_draws(), group = example_group_data())

# change the plot to have facet labels "apples" and "oranges" instead of "GroupA" and "GroupB"
pgroup <- facet_relabel_gg(pgroup, labels = c("GroupA" = "apples", "GroupB" = "oranges"))

From the proposed new doc:

  • facet_relabel_gg is atypical in that it accepts a ggplot object as input (so it can detect the variable currently used for faceting) and returns a modified version of the same ggplot object as its output (with update facet labels). The ... can be use with facet_relabel_gg to manually pass other arguments to facet_wrap or facet_grid other than "facets" and "scales" arguments, which are automatically inferred from the plot object.

  • facet_vars takes a ggplot object as input and returns a character vector indicating the name of the variable(s) bayesplot uses internally to create facets (if any). If facet_relabel_gg isn't flexible enough to relabel the facets how you want then facet_vars gives you the info you need to add facet_wrap (or facet_grid) to the object yourself. The "scales" attribute of the facet_vars result indicates the value bayesplot used for the scales argument to facet_wrap (or facet_grid).

@jgabry jgabry requested a review from tjmahr October 23, 2018 19:06
@jgabry jgabry added the feature label May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants