Reputation: 1
I am making multiple upset plots using the UpsetR package and will combine them using grid.arrange
to make a single figure. Is it possible to coerce the order of the intersections so that they are identical between plots?
By default, it orders the bars by frequency, but you can also specify order.by = “degree”
to order bars by number of intersecting sets. However, it does not always put bars of equivalent degree in the same order, and I have not found how to manually specify the intersection order when assigning the plot as an object and looking through the list of features. Below is an example.
listInput1 <- 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),
four = c(1, 11, 14))
listInput2 <- list(one = c(1, 2, 4, 6, 7, 9, 11, 12, 13),
two = c(1, 2, 4, 5, 10, 13, 14),
three = c(1, 3, 6, 7, 8, 9, 10, 12, 13),
four = c(1, 2, 3, 4, 5, 6, 7, 8, 9))
listInput3 <- list(one = c(1, 2, 4, 6, 8, 9, 11, 12, 13),
two = c(1, 2, 4, 5, 10, 13, 14),
three = c(1, 2, 3, 6, 7, 8, 9, 10, 12, 13, 14),
four = c(2, 6, 9, 11, 12))
listInput4 <- list(one = c(1, 2, 3, 4, 6, 8, 9, 11, 12, 13, 15, 16, 17),
two = c(1, 2, 3, 4, 5, 7, 10, 13, 14),
three = c(1, 2, 3, 6, 7, 8, 9, 10, 12, 13, 14),
four = c(4, 5, 6, 10, 11, 12))
plot.ls <- list(
p1 = upset(fromList(listInput1), order.by = "degree", sets = c("four", "three", "two", "one"), keep.order = TRUE, empty.intersections = "on"),
p2 = upset(fromList(listInput2), order.by = "degree", sets = c("four", "three", "two", "one"), keep.order = TRUE, empty.intersections = "on"),
p3 = upset(fromList(listInput3), order.by = "degree", sets = c("four", "three", "two", "one"), keep.order = TRUE, empty.intersections = "on"),
p4 = upset(fromList(listInput4), order.by = "degree", sets = c("four", "three", "two", "one"), keep.order = TRUE, empty.intersections = "on")
)
for (v in names(plot.ls)) {
print(plot.ls[[v]])
grid.text(v, x = 0.65, y=0.97, gp = gpar(fontsize = 20))
grid.edit('arrange', name = v)
vp <- grid.grab()
plot.ls[[v]] <- vp
}
grid.arrange(grobs = plot.ls, ncol = 2)
Ideally, I would have the set intersections in the following order for all plots: one&two, one, two, one&three, one&four, one&two&three, one&two&four, one&two&three&four, two&three&four, one&three&four, two&three, two&four, four, three, three&four. Is there any way to do this?
Upvotes: 0
Views: 4011
Reputation: 589
I had the same problem! I think the easiest solution would something like this (i.e., specify intersections
order instead sets
one... a bit more tedious, but it works):
plot.ls <- list(
p1 = upset(fromList(listInput1), order.by = "degree", keep.order = TRUE, empty.intersections = "on",
intersections = list(list("one", "two"), list("one"), list("two"), list("one", "three"), list("one", "four"), list("one", "two", "three"), list("one", "two", "four"), list("one", "two", "three", "four"), list("two", "three", "four"), list("one", "three", "four"), list("two", "three"), list("two", "four"), list("four"), list("three"), list("three", "four"))),
p2 = upset(fromList(listInput2), order.by = "degree", keep.order = TRUE, empty.intersections = "on",
intersections = list(list("one", "two"), list("one"), list("two"), list("one", "three"), list("one", "four"), list("one", "two", "three"), list("one", "two", "four"), list("one", "two", "three", "four"), list("two", "three", "four"), list("one", "three", "four"), list("two", "three"), list("two", "four"), list("four"), list("three"), list("three", "four"))),
p3 = upset(fromList(listInput3), order.by = "degree", keep.order = TRUE, empty.intersections = "on",
intersections = list(list("one", "two"), list("one"), list("two"), list("one", "three"), list("one", "four"), list("one", "two", "three"), list("one", "two", "four"), list("one", "two", "three", "four"), list("two", "three", "four"), list("one", "three", "four"), list("two", "three"), list("two", "four"), list("four"), list("three"), list("three", "four"))),
p4 = upset(fromList(listInput4), order.by = "degree", keep.order = TRUE, empty.intersections = "on",
intersections = list(list("one", "two"), list("one"), list("two"), list("one", "three"), list("one", "four"), list("one", "two", "three"), list("one", "two", "four"), list("one", "two", "three", "four"), list("two", "three", "four"), list("one", "three", "four"), list("two", "three"), list("two", "four"), list("four"), list("three"), list("three", "four")))
)
Upvotes: 1