const-ae / const-ae/ggupset

Specifiying stat = 'identity' breaks order_by

Open
#42 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
R
Stars
399
Forks
32
PR merge metrics
No merged PRs in 30d

Description

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')

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the two pipelines in the issue using scale_x_upset(order_by = 'freq') and compare them with stat = 'identity' and unit weights. Start at the scale_x_upset entry point and trace how frequency and degree ordering are calculated for each geom_bar path. Done means both examples produce identical bar ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.