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

Specifiying stat = 'identity' breaks order_by #42

Open
liamhaller opened this issue Nov 3, 2023 · 0 comments
Open

Specifiying stat = 'identity' breaks order_by #42

liamhaller opened this issue Nov 3, 2023 · 0 comments

Comments

@liamhaller
Copy link

Hi, first off thank you for your work on the package. I am experimenting by trying to add survey weights to the graph and noticed that once stat = 'identity' is specified scale_x_upset is no longer able to order by freq and inconsistently orders by 'degree'.

I would expect the two graphs below to be identical given the only difference is that the values for geom_bar are summarised in advance and the value for the weights are 1 however, the order of the bars remains different.

Thank you in advance!

df <- data.frame(matrix(data = seq(1:500), nrow = 500))
   df$a <- sample( c(0, 1), 500, replace=TRUE, prob=c(0.70, .30))
   df$b <- sample( c(0, 1), 500, replace=TRUE, prob=c(0.40, .60))
   df$c <- sample( c(0, 1), 500, replace=TRUE, prob=c(0.90, .10))
   df$d <- sample( c(0, 1), 500, replace=TRUE, prob=c(0.05, .95))
   df$e <- sample( c(0, 1), 500, replace=TRUE, prob=c(0.50, .50))
   df$weights <- 1
   df <- df %>% select(-1)


   df %>%   
     as_tibble(rownames = "respondent") %>% 
     pivot_longer(-respondent , names_to = 'question') %>% 
     filter(value != 0) %>% 
     group_by(respondent) %>% 
     summarize(question = list(question)) %>% 
     ggplot(aes(x = question)) +
     geom_bar() +
     scale_x_upset(order_by = 'freq')
   
  df %>% 
     as_tibble(rownames = "respondent") %>% 
     pivot_longer(-c(respondent, weights) , names_to = 'question') %>% 
     filter(value != 0) %>% 
     group_by(respondent, weights) %>% 
     summarize(question = list(question)) %>% 
     group_by(question) %>% 
     summarise(count = sum(weights)) %>% 
     ggplot(aes(x = question, y = count)) +
     geom_bar(stat = 'identity') +
     scale_x_upset(order_by = 'freq')

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

1 participant