krassowski / complex-upset

A library for creating complex UpSet plots with ggplot2 geoms
MIT License
453 stars 28 forks source link

Coloring multiple *specific* insections #193

Open ashleyhappiness opened 6 months ago

ashleyhappiness commented 6 months ago

Objective I would like to highlight certain intersect on a graph. To use the movie example, I want to have "Romance", "Drama" and "Romance + Drama" movies be highlighted in yellow, "Action", "Animation" and "Action + Animation" in green and "Documentary" in blue and completely ignore Comedy (but leave it shown). I can get one intersect to be highlighted but when I add in a second one, the intersect bar graph expands beyond the original container. I am not interested in coloring by degree.

Code

upset(trans_pro,
      treatments_pro,
      name = "treatment",
      width_ratio = 0.2,
      sort_sets = FALSE,
      set_sizes = FALSE,
      matrix = intersection_matrix(
        geom = geom_point(
          shape='square',
          size=3.5)
        ),
      queries = list(
        upset_query(
          intersect = c("NCT-pro-cold"),
          color="blue",
          fill="blue",
          only_components=c('intersections_matrix', 'Intersection size')
        ),
        upset_query(
          intersect = c("RBC2-pro-hot","NCT-pro-hot"),
          color="firebrick",
          fill="firebrick",
          only_components=c('intersections_matrix', 'Intersection size')
        )
      )
      )

Screenshot or illustration image Above is the problem that I am experiencing.

Context (required)

ComplexUpset version: ‘1.3.3’

R version details ```R $platform [1] "x86_64-w64-mingw32" $arch [1] "x86_64" $os [1] "mingw32" $crt [1] "ucrt" $system [1] "x86_64, mingw32" $status [1] "" $major [1] "4" $minor [1] "3.2" $year [1] "2023" $month [1] "10" $day [1] "31" $`svn rev` [1] "85441" $language [1] "R" $version.string [1] "R version 4.3.2 (2023-10-31 ucrt)" $nickname [1] "Eye Holes" ```
R session information ```R R version 4.3.2 (2023-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045) Matrix products: default locale: [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 LC_MONETARY=English_United States.utf8 [4] LC_NUMERIC=C LC_TIME=English_United States.utf8 time zone: America/Chicago tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2 readr_2.1.5 [7] tibble_3.2.1 ggplot2_3.4.4 tidyverse_2.0.0 tidyr_1.3.1 ComplexUpset_1.3.3 loaded via a namespace (and not attached): [1] gtable_0.3.4 compiler_4.3.2 tidyselect_1.2.0 scales_1.3.0 yaml_2.3.8 fastmap_1.1.1 R6_2.5.1 [8] labeling_0.4.3 generics_0.1.3 patchwork_1.2.0 knitr_1.45 munsell_0.5.0 pillar_1.9.0 tzdb_0.4.0 [15] rlang_1.1.2 utf8_1.2.4 stringi_1.8.3 xfun_0.41 pkgload_1.3.4 timechange_0.3.0 cli_3.6.1 [22] withr_3.0.0 magrittr_2.0.3 digest_0.6.33 grid_4.3.2 rstudioapi_0.15.0 hms_1.1.3 lifecycle_1.0.4 [29] vctrs_0.6.4 evaluate_0.23 glue_1.6.2 farver_2.1.1 fansi_1.0.5 colorspace_2.1-0 rmarkdown_2.25 ```
drychkov commented 3 months ago

I've got the same issue. Were you able to figure out at least a temporary fix?

drychkov commented 3 months ago

Got it! Specifying a bar width inside both upset_query() fixed the issue for me.

For example, upset_query( intersect = c("RBC2-pro-hot","NCT-pro-hot"), color="firebrick", fill="firebrick", only_components=c('intersections_matrix', 'Intersection size'), width = 0.9 )