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

Error when variable used for color is a factor and contains unused levels #47

Open
jbengler opened this issue Jan 16, 2025 · 1 comment
Labels
bug an unexpected problem or unintended behavior

Comments

@jbengler
Copy link
Owner

Reprex

library(tidyverse)
library(tidyplots)

# works
study %>% 
  tidyplot(x = treatment, y = score, color = treatment) %>% 
  add_mean_dot()

# works
study %>% 
  filter(treatment != "A") %>% 
  tidyplot(x = treatment, y = score, color = treatment) %>% 
  add_mean_dot()

# works
study %>% 
  mutate(treatment = factor(treatment)) %>% 
  tidyplot(x = treatment, y = score, color = treatment) %>% 
  add_mean_dot()

# error
study %>% 
  mutate(treatment = factor(treatment)) %>% 
  filter(treatment != "A") %>% 
  tidyplot(x = treatment, y = score, color = treatment) %>% 
  add_mean_dot()

# works
study %>% 
  mutate(treatment = factor(treatment)) %>% 
  filter(treatment != "A") %>% 
  mutate(treatment = fct_drop(treatment)) %>% 
  tidyplot(x = treatment, y = score, color = treatment) %>% 
  add_mean_dot()
@jbengler jbengler added the bug an unexpected problem or unintended behavior label Jan 16, 2025
@jbengler
Copy link
Owner Author

One option would be to routinely run fct_drop() on the color variable when starting the plot with tidyplot().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

1 participant