UpSetR icon indicating copy to clipboard operation
UpSetR copied to clipboard

Find the max number of intersects in an UpSetR plot.

Open makis23 opened this issue 6 years ago • 2 comments

I have the movies dataframe from movies <- read.csv( system.file("extdata", "movies.csv", package = "UpSetR"), header=T, sep=";" )

and then I use UpSetR to plot it:

library(UpSetR)
upset(data = movies,
      nintersects = NA, 
      order.by='freq',
      matrix.color = 'black',
      shade.alpha = 0.5,
      scale.intersections=ifelse(scaleOfYAxis,'log2','identity'))

As you can see I can set the number of intersects (number of vertical bars) to NA which gives me the maximum number of intersects available. My question is how I could extract this number without of course having to count the number of bars after creating the plot.

r

makis23 avatar Dec 24 '18 16:12 makis23

Hello makis23 and others, I also want the same info. Did you get this without manually count the bars? If we do not plot the data it gives us the following matrix: `> sc1=upset(plsmo1,nsets = 17,nintersects = NA,text.scale = 2)

sc1$Main_bar TableGrob (12 x 9) "layout": 18 grobs z cells name grob 1 0 ( 1-12, 1- 9) background rect[plot.background..rect.3682] 2 5 ( 6- 6, 4- 4) spacer zeroGrob[NULL] 3 7 ( 7- 7, 4- 4) axis-l absoluteGrob[GRID.absoluteGrob.3673] 4 3 ( 8- 8, 4- 4) spacer zeroGrob[NULL] 5 6 ( 6- 6, 5- 5) axis-t zeroGrob[NULL] 6 1 ( 7- 7, 5- 5) panel gTree[panel-1.gTree.3664] 7 9 ( 8- 8, 5- 5) axis-b absoluteGrob[GRID.absoluteGrob.3666] 8 4 ( 6- 6, 6- 6) spacer zeroGrob[NULL] 9 8 ( 7- 7, 6- 6) axis-r zeroGrob[NULL] 10 2 ( 8- 8, 6- 6) spacer zeroGrob[NULL] 11 10 ( 5- 5, 5- 5) xlab-t zeroGrob[NULL] 12 11 ( 9- 9, 5- 5) xlab-b zeroGrob[NULL] 13 12 ( 7- 7, 3- 3) ylab-l titleGrob[axis.title.y.left..titleGrob.3676] 14 13 ( 7- 7, 7- 7) ylab-r zeroGrob[NULL] 15 14 ( 4- 4, 5- 5) subtitle zeroGrob[plot.subtitle..zeroGrob.3678] 16 15 ( 3- 3, 5- 5) title zeroGrob[plot.title..zeroGrob.3677] 17 16 (10-10, 5- 5) caption zeroGrob[plot.caption..zeroGrob.3680] 18 17 ( 2- 2, 2- 2) tag zeroGrob[plot.tag..zeroGrob.3679]`

Is there any way to find total intersections without counting the vertical bar? Best, Zillur

zillurbmb51 avatar Nov 22 '19 15:11 zillurbmb51

Try this example:

# Example input as list
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))

x <- upset(fromList(listInput))
x$New_data
#    one two three
# 1    1   1     1
# 2    1   1     0
# 3    1   0     0
# 4    1   1     1
# 5    1   0     1
# 6    1   0     1
# 7    1   0     0
# 8    1   0     1
# 9    1   0     1
# 10   0   1     0
# 11   0   1     1
# 12   0   0     1
# 13   0   0     1

nrow(unique(x$New_data))
#[1] 7

But for movies data it shows 1 extra, it should be 27, but returns 28.

x <- upset(data = movies,
           nintersects = NA, 
           order.by='freq',
           matrix.color = 'black',
           shade.alpha = 0.5)

nrow(unique(x$New_data[, x$labels ]))
# [1] 28

zx8754 avatar Nov 26 '20 21:11 zx8754