Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 204798

UpsetR: manually order set intersections to align multiple upset plots

$
0
0

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?


Viewing all articles
Browse latest Browse all 204798

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>