title: Complex Upset in R: Sort ascending by degree and descending within degree groups?
body: <p>Following the method outlined <a href="https://github.com/krassowski/complex-upset/issues/132" rel="nofollow noreferrer">here</a>, the following code produces a complex upset plot where bars are colored by degree groups (e.g., number of combinations):</p>
  <pre><code>library(tidyverse)
  library(ComplexUpset)
  
  movies = as.data.frame(ggplot2movies::movies)
  movies[movies$mpaa == '', 'mpaa'] = NA
  movies = na.omit(movies)
  genres = colnames(movies)[18:24]
  
  query_by_degree = function(data, groups, params_by_degree, ...) {
    intersections = unique(upset_data(data, groups)$plot_intersections_subset)
    lapply(
      intersections,
      FUN=function(x) {
        members = ComplexUpset:::get_intersection_members(x)[[1]]
        degree = as.character(ComplexUpset:::calculate_degree(x))
        if (!(degree %in% names(params_by_degree))) {
          stop(
            paste('Missing specification of params for degree', degree)
          )
        }
        args = c(
          list(intersect=members, ...),
          params_by_degree[[degree]]
        )
        do.call(upset_query, args)
      }
    )
  }
  
  upset(
    movies,
    genres,
    width_ratio=0.1,
    sort_intersections=&quot;descending&quot;,
    sort_sets=&quot;ascending&quot;,
    sort_intersections_by=c('degree', 'cardinality'),
    queries=query_by_degree(
      movies, genres,
      params_by_degree=list(
        '1'=list(color='red', fill='red'),
        '2'=list(color='purple', fill='purple'),
        '3'=list(color='blue', fill='blue'),
        '4'=list(color='green', fill='green'),
        '0'=list(color='orange', fill='orange')
      ),
      only_components=c(&quot;intersections_matrix&quot;, &quot;Intersection size&quot;)
    )
  )
  </code></pre>
  <p>Which produces:
  <a href="https://i.stack.imgur.com/Dl3fo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dl3fo.png" alt="enter image description here" /></a></p>
  <p>However, there does not seem to be a way to sort the colored bars first by degree descending, meaning the groups go from 0 to 4 and then, within those degree groups sort descending to make a plot that looks like this:</p>
  <p><a href="https://i.stack.imgur.com/1jgMh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1jgMh.png" alt="enter image description here" /></a></p>
  <p>Any suggestions on how to achieve this?</p>