hms-dbmi / UpSetR

An R implementation of the UpSet set visualization technique published by Lex, Gehlenborg, et al..
https://cran.rstudio.com/web/packages/UpSetR
Other
763 stars 156 forks source link

"sets" must be the first column of metadata to make a metadata plot #219

Open maureencarey opened 3 years ago

maureencarey commented 3 years ago

This works:

df = data.frame(sample1 = c(0,1,1,0),sample2 = c(1,0,1,0),sample3 = c(0,1,0,1))
rownames(df) = c("one","two","three","four")
metadata = data.frame(sets = c("sample1","sample2","sample3"), variable = c("grp1","grp1","grp2"))

upset(df, main.bar.color = "black", 
      set.metadata = list(data = metadata, 
                          plots = list(list(type = "matrix_rows", column = "variable", alpha = 0.5,
                                            colors = c(grp1 = "green", grp2 = "navy")))))

but if you change the order of the metadata columns, e.g.:


metadata = metadata[c("variable","sets")]

an error pops up:


upset(df, main.bar.color = "black", 
      set.metadata = list(data = metadata, 
                          plots = list(list(type = "matrix_rows", column = "variable", alpha = 0.5,
                                            colors = c(grp1 = "green", grp2 = "navy")))))
Error in colors[[j]] : 
  attempt to select less than one element in integerOneIndex

the error message is somewhat counterintuitive to me, so I thought I'd post it in case anyone else runs into the same issue!