complex-upset icon indicating copy to clipboard operation
complex-upset copied to clipboard

Order intersections

Open eds-slim opened this issue 4 years ago • 3 comments

Is it possible to prespecify the order of the intersections? I know there are option sort_intersections and sort_intersections_by but they don't allow ordering by, say, a factor in the input data frame. Thanks.

eds-slim avatar Jun 09 '20 11:06 eds-slim

Thank you for the feedback. I can imagine having an additional argument for that, but I am not sure how would that work with a factor from the data frame. Could you create a short example to demonstrate the desired behaviour, please?

Edit: You could base of this minimal test case:

df = data.frame(
    a=c(TRUE, FALSE, TRUE, TRUE),
    b=c(TRUE, TRUE, TRUE, TRUE),
    c=c(FALSE, TRUE, FALSE, FALSE),
    d=c(FALSE, FALSE, FALSE, TRUE)
)
upset(df, c('a', 'b', 'c', 'd'))

krassowski avatar Jun 09 '20 11:06 krassowski

Thanks for yoru reply.

I would imagine something like

df = data.frame(
  a=c(TRUE, FALSE, TRUE, TRUE),
  b=c(TRUE, TRUE, TRUE, TRUE),
  c=c(FALSE, TRUE, FALSE, FALSE),
  d=c(FALSE, FALSE, FALSE, TRUE)
)

df$order <- c(3,2,3,1)

upset(df, c('a', 'b', 'c', 'd'), ordering = 'order')

putting the intersection of size two last in the plot.

I suppose, one would have to check that the ordering factor is valid in the sense that it takes unique values witin each intersection, but that should not be too difficult.

eds-slim avatar Jun 09 '20 11:06 eds-slim

I've resolved the issue by simply replacing sorted_intersections with with_sizes %>% dplyr::select(order, intersection) %>% distinct() %>% arrange(order) %>% pull("intersection") at the end of upset_data(), and then calling upset with sort_intersections = 'ascending'.

eds-slim avatar Jun 11 '20 07:06 eds-slim