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_signif does not plot comparison on the facetted plot with free x scale #118

Open
Dobrokhotov1989 opened this issue Jul 25, 2022 · 2 comments

Comments

@Dobrokhotov1989
Copy link

So, as stated in the subject - when I use scales = 'free_x' in facet_grid(), geom_signif fails

Reprex

Data prep

library(tidyverse)
library(ggsignif)

# Prepare representative data
edited_mpg <-  mpg %>%
  filter(cyl %in% c(4, 6)) %>%
  mutate( year = case_when(
    cyl == 4 ~ year + 2,
    TRUE ~ as.numeric(year)
  )) 

This works

# Plot with fixed scales in facet_grid() works fine
edited_mpg %>%
  ggplot(aes(x = as.factor(year),
             y = hwy)) +
  geom_point() +
  geom_signif(comparison = list(c(1, 3),
                                c(2, 4)),
              test = 't.test') +
  facet_grid(cols = vars(cyl)) +
  coord_cartesian(ylim = c(15, 50))

This doesn't work

# Same as above but 'free_x' scales in facet_grid() does not work
edited_mpg %>%
  ggplot(aes(x = as.factor(year),
             y = hwy)) +
  geom_point() +
  geom_signif(comparison = list(c(1, 3),
                                c(2, 4)),
              test = 't.test') +
  coord_cartesian(ylim = c(15, 50)) +
  facet_grid(cols = vars(cyl),
             scales = 'free_x')
#> Warning: Computation failed in `stat_signif()`:
#> not enough 'y' observations
#> Computation failed in `stat_signif()`:
#> not enough 'y' observations

Created on 2022-07-25 by the reprex package (v2.0.1)

@drfalco
Copy link

drfalco commented Jun 25, 2023

@Dobrokhotov1989 Could you solve or work-around this issue?

@Dobrokhotov1989
Copy link
Author

Hi @drfalco,
Sorry I don't remember what I'm end up with. Most likely I did it in some manual way, but I'm not sure

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