From d0f407a4b4bd2b47fd5318403527b6ae4925ebc7 Mon Sep 17 00:00:00 2001 From: krassowski Date: Sat, 1 May 2021 10:17:31 +0100 Subject: [PATCH] Allow to query by sets on intersections matrix, move highlights layer to top --- DESCRIPTION | 2 +- NEWS.md | 16 +- R/upset.R | 26 +- .../example-0-2-region-selection-modes-3.svg | 16 +- .../example-4-3-logarithmic-scale-1.svg | 10 + ...-4-adjusting-the-intersection-matrix-1.svg | 4 +- .../example-7-highlighting-queries-1.svg | 14 +- .../example-9-1-grouping-intersections-1.svg | 100 +++++-- ...are-visible-on-top-of-highlighted-bars.svg | 2 +- .../hyphenated-variables-can-be-queried.svg | 8 +- ...ltiple-competing-queries-work-together.svg | 12 +- ...-the-same-kind-highlight-intersections.svg | 8 +- ...-different-aes-highlight-intersections.svg | 8 +- ...ight-both-intersection-size-and-matrix.svg | 8 +- ...-be-highlighted-on-intersection-matrix.svg | 267 ++++++++++++++++++ tests/testthat/test-other-visual.R | 25 ++ 16 files changed, 453 insertions(+), 73 deletions(-) create mode 100644 tests/figs/other-visual/sets-can-be-highlighted-on-intersection-matrix.svg diff --git a/DESCRIPTION b/DESCRIPTION index 58b610d..25d947d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: ComplexUpset Type: Package Title: Create Complex UpSet Plots Using 'ggplot2' Components -Version: 1.2.1 +Version: 1.2.1.9000 Authors@R: person( "Michał", "Krassowski", email = "krassowski.michal+r@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9638-7785")) diff --git a/NEWS.md b/NEWS.md index fa9dbd9..53102e8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,19 @@ +# Version 1.3.0 + +unreleased + +Changes: +- sets on intersection matrix can now be highlighted using `upset_query()` #115 + +Bug fixes: +- alleviate visual glitch of `geom_segment` in intersections matrix showing up with an outline #113 + # Version 1.2.1 2021-04-25 Bug fixes: -- fixed metadata order in data frame returned by `arrange_venn()` function #116 +- fixed metadata order in data frame returned by `arrange_venn()` function #116 # Version 1.2.0 @@ -20,8 +30,8 @@ Major improvements: - stripes color and other attributes can now be mapped to data #111 Minor improvements: -- data.table can be passed instead of data.frame (the conversion will be performed atuomatically) #105 -- warning will be shown if a vecotor is provided instead of a list to the `intersections` argument #109 +- data.table can be passed instead of data.frame (the conversion will be performed automatically) #105 +- warning will be shown if a vector is provided instead of a list to the `intersections` argument #109 - when `intersections` argument includes sets not specified in `intersect`, a warning will be issued and execution will proceed as if those were included in `intersect` #109 - when incorrect names of sets are passed to `intersections` argument, those will be highlighted and plotting will be aborted #109 diff --git a/R/upset.R b/R/upset.R index 9087abd..5cac56e 100644 --- a/R/upset.R +++ b/R/upset.R @@ -980,14 +980,20 @@ upset = function( matrix_intersect_queries = intersect_queries(queries_for(queries, 'intersections_matrix'), data) matrix_group_by_queries = group_by_queries(queries_for(queries, 'intersections_matrix'), data$sanitized_labels) + matrix_set_queries = set_queries(queries_for(queries, 'intersections_matrix'), data$sanitized_labels) intersection_query_matrix = get_highlights_data(data$matrix_frame, 'intersection', matrix_intersect_queries) group_query_matrix = get_highlights_data(data$matrix_frame, 'group_by_group', matrix_group_by_queries) + set_query_matrix = get_highlights_data(data$matrix_frame, 'group', matrix_set_queries) + query_matrix = merge_rows( - intersection_query_matrix, - group_query_matrix - ) + merge_rows( + intersection_query_matrix, + group_query_matrix + ), + set_query_matrix + ) query_matrix = query_matrix[query_matrix$value == TRUE, ] @@ -1019,13 +1025,6 @@ upset = function( size=dot_size, na.rm=TRUE )), - # the highlighted dot - highlight_layer( - intersections_matrix$geom, - geom_point, - query_matrix, - args=list(size=dot_size) - ), # interconnectors on the dots list(intersections_matrix$segment * geom_segment(aes( x=intersection, @@ -1047,6 +1046,13 @@ upset = function( ), na.rm=TRUE ) + ), + # the highlighted dot + highlight_layer( + intersections_matrix$geom, + geom_point, + query_matrix, + args=list(size=dot_size) ) ) diff --git a/tests/figs/examples/example-0-2-region-selection-modes-3.svg b/tests/figs/examples/example-0-2-region-selection-modes-3.svg index ab3c7bf..3488dc1 100644 --- a/tests/figs/examples/example-0-2-region-selection-modes-3.svg +++ b/tests/figs/examples/example-0-2-region-selection-modes-3.svg @@ -170,8 +170,6 @@ - - @@ -195,6 +193,8 @@ + + @@ -364,8 +364,6 @@ - - @@ -389,6 +387,8 @@ + + @@ -566,8 +566,6 @@ - - @@ -591,6 +589,8 @@ + + @@ -779,8 +779,6 @@ - - @@ -804,6 +802,8 @@ + + diff --git a/tests/figs/examples/example-4-3-logarithmic-scale-1.svg b/tests/figs/examples/example-4-3-logarithmic-scale-1.svg index 17f890f..22bdd92 100644 --- a/tests/figs/examples/example-4-3-logarithmic-scale-1.svg +++ b/tests/figs/examples/example-4-3-logarithmic-scale-1.svg @@ -406,6 +406,16 @@ + + + + + + + + + + diff --git a/tests/figs/examples/example-5-4-adjusting-the-intersection-matrix-1.svg b/tests/figs/examples/example-5-4-adjusting-the-intersection-matrix-1.svg index e2492e3..661486e 100644 --- a/tests/figs/examples/example-5-4-adjusting-the-intersection-matrix-1.svg +++ b/tests/figs/examples/example-5-4-adjusting-the-intersection-matrix-1.svg @@ -341,8 +341,6 @@ - - @@ -411,6 +409,8 @@ + + Look here → diff --git a/tests/figs/examples/example-7-highlighting-queries-1.svg b/tests/figs/examples/example-7-highlighting-queries-1.svg index e895231..307a1fb 100644 --- a/tests/figs/examples/example-7-highlighting-queries-1.svg +++ b/tests/figs/examples/example-7-highlighting-queries-1.svg @@ -523,8 +523,6 @@ - - @@ -593,6 +591,18 @@ + + + + + + + + + + + + diff --git a/tests/figs/examples/example-9-1-grouping-intersections-1.svg b/tests/figs/examples/example-9-1-grouping-intersections-1.svg index 7987073..23ebf1a 100644 --- a/tests/figs/examples/example-9-1-grouping-intersections-1.svg +++ b/tests/figs/examples/example-9-1-grouping-intersections-1.svg @@ -251,32 +251,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -339,6 +313,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/figs/other-visual/counts-are-visible-on-top-of-highlighted-bars.svg b/tests/figs/other-visual/counts-are-visible-on-top-of-highlighted-bars.svg index aafcca1..1736489 100644 --- a/tests/figs/other-visual/counts-are-visible-on-top-of-highlighted-bars.svg +++ b/tests/figs/other-visual/counts-are-visible-on-top-of-highlighted-bars.svg @@ -295,7 +295,6 @@ - @@ -347,6 +346,7 @@ + diff --git a/tests/figs/other-visual/hyphenated-variables-can-be-queried.svg b/tests/figs/other-visual/hyphenated-variables-can-be-queried.svg index b8e0162..d271484 100644 --- a/tests/figs/other-visual/hyphenated-variables-can-be-queried.svg +++ b/tests/figs/other-visual/hyphenated-variables-can-be-queried.svg @@ -177,8 +177,6 @@ - - @@ -193,6 +191,12 @@ + + + + + + diff --git a/tests/figs/other-visual/multiple-competing-queries-work-together.svg b/tests/figs/other-visual/multiple-competing-queries-work-together.svg index 83309dc..7af5e38 100644 --- a/tests/figs/other-visual/multiple-competing-queries-work-together.svg +++ b/tests/figs/other-visual/multiple-competing-queries-work-together.svg @@ -298,12 +298,6 @@ - - - - - - @@ -360,6 +354,12 @@ + + + + + + diff --git a/tests/figs/other-visual/multiple-queries-of-the-same-kind-highlight-intersections.svg b/tests/figs/other-visual/multiple-queries-of-the-same-kind-highlight-intersections.svg index f94652e..09507fc 100644 --- a/tests/figs/other-visual/multiple-queries-of-the-same-kind-highlight-intersections.svg +++ b/tests/figs/other-visual/multiple-queries-of-the-same-kind-highlight-intersections.svg @@ -294,10 +294,6 @@ - - - - @@ -352,6 +348,10 @@ + + + + diff --git a/tests/figs/other-visual/multiple-queries-with-different-aes-highlight-intersections.svg b/tests/figs/other-visual/multiple-queries-with-different-aes-highlight-intersections.svg index 93e980c..630e075 100644 --- a/tests/figs/other-visual/multiple-queries-with-different-aes-highlight-intersections.svg +++ b/tests/figs/other-visual/multiple-queries-with-different-aes-highlight-intersections.svg @@ -295,10 +295,6 @@ - - - - @@ -353,6 +349,10 @@ + + + + diff --git a/tests/figs/other-visual/queries-can-highlight-both-intersection-size-and-matrix.svg b/tests/figs/other-visual/queries-can-highlight-both-intersection-size-and-matrix.svg index 6079f83..cbbfa92 100644 --- a/tests/figs/other-visual/queries-can-highlight-both-intersection-size-and-matrix.svg +++ b/tests/figs/other-visual/queries-can-highlight-both-intersection-size-and-matrix.svg @@ -296,10 +296,6 @@ - - - - @@ -354,6 +350,10 @@ + + + + diff --git a/tests/figs/other-visual/sets-can-be-highlighted-on-intersection-matrix.svg b/tests/figs/other-visual/sets-can-be-highlighted-on-intersection-matrix.svg new file mode 100644 index 0000000..93680e0 --- /dev/null +++ b/tests/figs/other-visual/sets-can-be-highlighted-on-intersection-matrix.svg @@ -0,0 +1,267 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1581 +1213 +1103 +480 +385 +151 +284 +18 + + + + + +0 +500 +1000 +1500 +Intersection size + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +500 +1000 +1500 +2000 +Set size + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Action +Comedy +Drama +group +Drama should be highlighted ONLY on intersection matrix +Comedy should be highlighted ONLY on set sizes +Action should be highlighted on BOTH +Sets can be highlighted on intersection matrix + diff --git a/tests/testthat/test-other-visual.R b/tests/testthat/test-other-visual.R index 14c16fb..84f64b8 100644 --- a/tests/testthat/test-other-visual.R +++ b/tests/testthat/test-other-visual.R @@ -473,3 +473,28 @@ test_that("Metadata gets properly reordered for Venn diagrams", { ) ) }) + + +test_that("Sets can be highlighted on intersection matrix", { + expect_doppelganger( + "Sets can be highlighted on intersection matrix", + upset( + movies, + c('Action', 'Comedy', 'Drama'), + min_size=10, + width_ratio=0.2, + queries=list( + upset_query(set='Action', color='orange', fill='orange'), + upset_query(set='Comedy', color='blue', fill='blue', only_components = 'overall_sizes'), + upset_query(set='Drama', color='coral3', fill='coral3', only_components = 'intersections_matrix') + ) + ) + labs( + caption=paste( + 'Drama should be highlighted ONLY on intersection matrix', + 'Comedy should be highlighted ONLY on set sizes', + 'Action should be highlighted on BOTH', + sep='\n' + ) + ) + ) +})