UpSetR sets.bar interacting different color and its sets intersections

2.1k views Asked by At

hello I am creating upsetr plot not able figure out how can I plot the data as show in below image enter image description here

I saw different plot making similar to this but not same, Can any one suggest me an easy way to do it and seen some of the threads not able reproduce few according my above image kind output

UpSetR group by color set

Use a color palette for matrix points in UpSetR

blog post

Thank you

1

There are 1 answers

0
krassowski On BEST ANSWER

You can reproduce this plot using ComplexUpset 1.3 or newer.

Prepare the dataset:

movies = ggplot2movies::movies
movies[movies$mpaa == '', 'mpaa'] = NA 
movies = movies[complete.cases(movies), ]

And plot:

upset(
  movies,
  c('Action', 'Comedy', 'Drama'),
  queries=list(
    upset_query(set='Action', fill='orange'),
    upset_query(set='Comedy', fill='blue'),
    upset_query(set='Drama', fill='coral3')
  ),
  base_annotations=list(
    'Intersection size'=(
        intersection_size(
        bar_number_threshold=1,  # show all numbers on top of bars
        width=0.5,   # reduce width of the bars
      )
      # add some space on the top of the bars
      + scale_y_continuous(expand=expansion(mult=c(0, 0.05)))
      + theme(
          # hide grid lines
          panel.grid.major=element_blank(),
          panel.grid.minor=element_blank(),
          # show axis lines
          axis.line=element_line(colour='black')
      )
    )
  ),
  stripes=upset_stripes(
    geom=geom_segment(size=12),  # make the stripes larger
    colors=c('grey95', 'white')
  ),
  # to prevent connectors from getting the colorured
  # use `fill` instead of `color`, together with `shape='circle filled'`
  matrix=intersection_matrix(
      geom=geom_point(
        shape='circle filled',
        size=3.5,
        stroke=0.45
      )
  ),
  set_sizes=(
    upset_set_size(geom=geom_bar(width=0.4))
    + theme(
      axis.line.x=element_line(colour='black'),
      axis.ticks.x=element_line()
    )
  ),
  sort_sets='ascending',
  sort_intersections='ascending'
)

UpSetR equivalent plot