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

geom_tukey() in ggplot facet_wrap #2

Closed
MikkelZ opened this issue Dec 13, 2023 · 5 comments
Closed

geom_tukey() in ggplot facet_wrap #2

MikkelZ opened this issue Dec 13, 2023 · 5 comments

Comments

@MikkelZ
Copy link

MikkelZ commented Dec 13, 2023

Is there a way to treat the plots in a facet as individuals, so that the significance letters reset from one plot to another?

@ethanbass
Copy link
Owner

ethanbass commented Dec 13, 2023

I'm not sure I understand what you mean. Can you give an example?
When using geom_tukey with facet_wrap, the call to facet_wrap has to come first as in the vignette.

For example if you have a plot "p":

p <- penguins |> tidyr::drop_na(sex, species) |> 
  ggplot(aes(x=species, y=body_mass_g)) +
  geom_boxplot() + 
  geom_jitter(col="slategray", alpha=0.6) +
  ylab("Body mass (g)") +
  xlab("Species") + egg::theme_article()

this first example will produce the correct plot:

p+ facet_wrap(~sex) +
  geom_tukey(where="whisker")

whereas this second plot will come at wonky because geom_tukey doesn't know you have facets when you call it.

p +   geom_tukey(where="whisker") +
  facet_wrap(~sex)

@MikkelZ
Copy link
Author

MikkelZ commented Dec 13, 2023 via email

@ethanbass
Copy link
Owner

ethanbass commented Dec 13, 2023

Ah I understand what you mean now. Thanks for the clarification. You can control this behavior with the type argument. The default is the two-way ANOVA. In this case, ggtukey will do a global test across all facets. To just test for differences within the facetted groups, you can select type = "one-way". I think this is the option you want.

@MikkelZ
Copy link
Author

MikkelZ commented Dec 14, 2023 via email

@ethanbass
Copy link
Owner

Excellent!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants