How to manually order the set size bar plot of UpsetR

2.7k views Asked by At

I have the following code:

library(UpSetR)

listInput <- list(one = c(1, 2, 3, 5, 7, 8, 11, 12, 13), 
                  two = c(1, 2, 4, 5, 10),
                  three = c(1, 5, 6, 7, 8, 9, 10, 12, 13))

upset(fromList(listInput))

which produces this plot:

enter image description here

As you can see currently the barplot on the left is ordered according to size. I'd like to order it from top to bottom as: three, two, one.

How can I achieve that?

2

There are 2 answers

1
GordonShumway On BEST ANSWER

You can manually order the sets by inputting them manually to set and setting keep.order=TRUE

upset(fromList(listInput[c(1,2,3)]), 
      keep.order = T, 
      sets = c("one", "two", "three"))

enter image description here

0
Ken Field On

To keep both parts of the plot in your pre-defined order, you also want to use the order.by = "degree" option.

upset(fromList(listInput[c(1,2,3)]), 
      keep.order = T, order.by = "degree",
      sets = c("one", "two", "three"))