krassowski/complex-upset

Set names on both sides of the intersection matrix

Julkut opened this issue · 2 comments

Hi.
Is there a way to duplicate the set names on both sides of the intersection matrix? I have quite a few intersections and would like to have set names both on the left and on the right hand side of the intersection matrix.
I would appreciate any advice.
Thanks beforehand!
Best,
Julia

A clean solution requires scale_discrete to accept sec.axis which is a change needed in ggplot2 itself. There is an issue open for this: tidyverse/ggplot2#3171 and in fact, as of today, it is the most requested issue in ggplot2 repository (you can go to the issue and upvote it too).

For now we can use a workaround from tidyverse/ggplot2#3171 (comment) (but it may stop working in future). It requires copy-pasting:

library(ggplot2)

guide_axis_label_trans <- function(label_trans = identity, ...) {
  axis_guide <- guide_axis(...)
  axis_guide$label_trans <- rlang::as_function(label_trans)
  class(axis_guide) <- c("guide_axis_trans", class(axis_guide))
  axis_guide
}

guide_train.guide_axis_trans <- function(x, ...) {
  trained <- NextMethod()
  trained$key$.label <- x$label_trans(trained$key$.label)
  trained
}

and then using it with ComplexUpset like this:

upset(
    movies, genres, name='genre', min_size=10,
    matrix=(
        intersection_matrix()
        + guides(y.sec=guide_axis_label_trans(identity))
    )
)

image

Is this what you were asking about?

Thank you very much! This helped!