<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/hacking-our-way-through-upsetr/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://feedproxy.google.com/~r/LIBDrstats/~3/8ZYTyu4yFIE/"> Rstats on LIBD rstats club</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>For our club meeting today we were going to summarize the <a rel="nofollow" href="https://www.thisismetis.com/demystifying-data-science" target="_blank">Demystifying Data Science</a> conference but we forgot that the videos are not released yet.</p>
<blockquote class="twitter-tweet">
<p lang="en" dir="ltr">Oops, we'll have to postpone our blog post. We didn't read the fine print that talk recordings will be available sometime next week. Sorry about that!</p>
<p>— LIBD rstats club (@LIBDrstats) <a rel="nofollow" href="https://twitter.com/LIBDrstats/status/1022862435869450240?ref_src=twsrc%5Etfw" target="_blank">July 27, 2018</a></p></blockquote>
<p></p>
<p>So we adjusted plans and decided to continue our work on the <em><a rel="nofollow" href="https://cran.r-project.org/package=UpSetR" target="_blank">UpSetR</a></em> <a></a>(<a rel="nofollow" href="http://github.com/hms-dbmi/UpSetR" target="_blank">Gehlenborg, 2016</a>) package by <a rel="nofollow" href="https://twitter.com/ngehlenborg" target="_blank">Nils Gehlenborg</a>.</p>
<blockquote class="twitter-tweet">
<p lang="en" dir="ltr">Yesterday we discussed various options for visualizing large numbers of overlapping groups. We explored uses of the <a rel="nofollow" href="https://twitter.com/hashtag/venneuler?src=hash&ref_src=twsrc%5Etfw" target="_blank">#venneuler</a> package from Lee Wilkinson and Simon Urbanek and the <a rel="nofollow" href="https://twitter.com/hashtag/UpSetR?src=hash&ref_src=twsrc%5Etfw" target="_blank">#UpSetR</a> package from Jake Conway, Alexander Lex, and <a rel="nofollow" href="https://twitter.com/ngehlenborg?ref_src=twsrc%5Etfw" target="_blank">@ngehlenborg</a>. <a rel="nofollow" href="https://twitter.com/hashtag/rstats?src=hash&ref_src=twsrc%5Etfw" target="_blank">#rstats</a> <a rel="nofollow" href="https://t.co/k55YfihmiP" target="_blank">pic.twitter.com/k55YfihmiP</a></p>
<p>— LIBD rstats club (@LIBDrstats) <a rel="nofollow" href="https://twitter.com/LIBDrstats/status/1007992479159812101?ref_src=twsrc%5Etfw" target="_blank">June 16, 2018</a></p></blockquote>
<p></p>
<div>
<h3>What you can currently do</h3>
<p>First, let’s install the version we used for this post:</p>
<pre><code>devtools::install_github('hms-dbmi/UpSetR@fe2812c')</code></pre>
<p>Our ultimate goal is to submit a pull request that enables <code>UpSetR</code> users to specify a color by row for the dots instead of the actual rows. We had already identified an example that we could work with.</p>
<pre><code>library('UpSetR')
movies &lt;- read.csv( system.file(&quot;extdata&quot;, &quot;movies.csv&quot;, package = &quot;UpSetR&quot;), 
                    header=T, sep=&quot;;&quot; )

require(ggplot2); require(plyr); require(gridExtra); require(grid);</code></pre>
<pre><code>## Loading required package: ggplot2</code></pre>
<pre><code>## Loading required package: plyr</code></pre>
<pre><code>## Loading required package: gridExtra</code></pre>
<pre><code>## Loading required package: grid</code></pre>
<pre><code>upset(movies, 
      sets = c(&quot;Action&quot;, &quot;Comedy&quot;, &quot;Drama&quot;), 
      order.by=&quot;degree&quot;, matrix.color=&quot;blue&quot;, point.size=5,
      sets.bar.color=c(&quot;maroon&quot;,&quot;blue&quot;,&quot;orange&quot;))</code></pre>
<p><img src="https://i1.wp.com/lieberinstitute.github.io/rstatsclub/post/2018-07-27-hacking-our-way-through-upsetr_files/figure-html/unnamed-chunk-2-1.png?w=450" data-recalc-dims="1"></p>
<p>We also explored the <a rel="nofollow" href="https://cran.rstudio.com/web/packages/UpSetR/vignettes/set.metadata.plots.html" target="_blank">set metadata vignette</a> that includes examples such as the following one.</p>
<pre><code>set.seed(20180727)

## Create the metadata object first
sets &lt;- names(movies[3:19])
avgRottenTomatoesScore &lt;- round(runif(17, min = 0, max = 90))
metadata &lt;- as.data.frame(cbind(sets, avgRottenTomatoesScore))
names(metadata) &lt;- c(&quot;sets&quot;, &quot;avgRottenTomatoesScore&quot;)
metadata$avgRottenTomatoesScore &lt;- as.numeric(as.character(metadata$avgRottenTomatoesScore))
Cities &lt;- sample(c(&quot;Boston&quot;, &quot;NYC&quot;, &quot;LA&quot;), 17, replace = T)
metadata &lt;- cbind(metadata, Cities)
metadata$Cities &lt;- as.character(metadata$Cities)
metadata[which(metadata$sets %in% c(&quot;Drama&quot;, &quot;Comedy&quot;, &quot;Action&quot;, &quot;Thriller&quot;, 
    &quot;Romance&quot;)), ]</code></pre>
<pre><code>##        sets avgRottenTomatoesScore Cities
## 1    Action                     68 Boston
## 4    Comedy                     40    NYC
## 7     Drama                     48     LA
## 13  Romance                     77 Boston
## 15 Thriller                     19    NYC</code></pre>
<pre><code>accepted &lt;- round(runif(17, min = 0, max = 1))
metadata &lt;- cbind(metadata, accepted)
metadata[which(metadata$sets %in% c(&quot;Drama&quot;, &quot;Comedy&quot;, &quot;Action&quot;, &quot;Thriller&quot;, 
    &quot;Romance&quot;)), ]</code></pre>
<pre><code>##        sets avgRottenTomatoesScore Cities accepted
## 1    Action                     68 Boston        0
## 4    Comedy                     40    NYC        1
## 7     Drama                     48     LA        0
## 13  Romance                     77 Boston        1
## 15 Thriller                     19    NYC        0</code></pre>
<pre><code>## Now make the plot
upset(movies, set.metadata = list(data = metadata, plots = list(list(type = &quot;hist&quot;, 
    column = &quot;avgRottenTomatoesScore&quot;, assign = 20), list(type = &quot;matrix_rows&quot;, 
    column = &quot;Cities&quot;, colors = c(Boston = &quot;green&quot;, NYC = &quot;navy&quot;, LA = &quot;purple&quot;), 
    alpha = 0.5))))</code></pre>
<p><img src="https://i2.wp.com/lieberinstitute.github.io/rstatsclub/post/2018-07-27-hacking-our-way-through-upsetr_files/figure-html/unnamed-chunk-3-1.png?w=450" data-recalc-dims="1"></p>
</div>
<div>
<h3>Hacking our way</h3>
<p>Using the <code>metadata</code> looked complicated to us and hopefully not necessary for what we are trying to accomplish. That is, we really wanted to change the colors of the circles in each row, not the rows themselves. So we found the GitHub repo with <a rel="nofollow" href="https://github.com/hms-dbmi/UpSetR" target="_blank">the code</a>, plugged a laptop to a TV and started exploring as a group. We went the rabbit hole to see how the <code>matrix.color</code> argument got used. To actually hack our way through, we downloaded the latest version of the code using <code>git</code>.</p>
<pre><code>git clone git@github.com:hms-dbmi/UpSetR.git
cd UpSetR</code></pre>
<p>Next, we created the objects that match the default arguments of <code>upset()</code> by finding and replacing commas by semi-colons. Well, not all of the commas. Also, for inputs that specified a vector (mostly 2 options), we chose the first one to match the default R behavior. This way we could execute them and have them in our session.</p>
<pre><code>## Default upset() arguments
nsets = 5; nintersects = 40; sets = NULL; keep.order = F; set.metadata = NULL; intersections = NULL;
matrix.color = &quot;gray23&quot;; main.bar.color = &quot;gray23&quot;; mainbar.y.label = &quot;Intersection Size&quot;; mainbar.y.max = NULL;
sets.bar.color = &quot;gray23&quot;; sets.x.label = &quot;Set Size&quot;; point.size = 2.2; line.size = 0.7;
mb.ratio = c(0.70,0.30); expression = NULL; att.pos = NULL; att.color = main.bar.color; order.by = 'freq';
decreasing = T; show.numbers = &quot;yes&quot;; number.angles = 0; group.by = &quot;degree&quot;;cutoff = NULL;
queries = NULL; query.legend = &quot;none&quot;; shade.color = &quot;gray88&quot;; shade.alpha = 0.25; matrix.dot.alpha =0.5;
empty.intersections = NULL; color.pal = 1; boxplot.summary = NULL; attribute.plots = NULL; scale.intersections = &quot;identity&quot;;
scale.sets = &quot;identity&quot;; text.scale = 1; set_size.angles = 0 ; set_size.show = FALSE </code></pre>
<p>Next, we did the same (commas to semicolons) for the inputs of the first example.</p>
<pre><code>## Initial inputs on the first example
movies &lt;- read.csv( system.file(&quot;extdata&quot;, &quot;movies.csv&quot;, package = &quot;UpSetR&quot;), 
                    header=T, sep=&quot;;&quot; )

## comma -> semicolon
data = movies; sets = c(&quot;Action&quot;, &quot;Comedy&quot;, &quot;Drama&quot;); 
      order.by=&quot;degree&quot;; matrix.color=&quot;blue&quot;; point.size=5;
      sets.bar.color=c(&quot;maroon&quot;,&quot;blue&quot;,&quot;orange&quot;)</code></pre>
<p>Now we were ready to start modifying some of the internal <em><a rel="nofollow" href="https://cran.r-project.org/package=UpSetR" target="_blank">UpSetR</a></em> (<a rel="nofollow" href="http://github.com/hms-dbmi/UpSetR" target="_blank">Gehlenborg, 2016</a>) code.</p>
</div>
<div>
<h3>Hacking internals</h3>
<p>The function <code>upset()</code> is pretty long and uses many un-exported functions from the package itself. In order to test thing quickly we added <code>UpSetR:::</code> calls before the un-exported functions. Here’s our modified version where we added a piece of code to modify the <code>Matrix_layout</code> object and add some colors.</p>
<pre><code>## Piece of code we introduced
for(i in 1:3) {
      j &lt;- which(Matrix_layout$y == i &amp; Matrix_layout$value == 1)
      if(length(j) > 0) Matrix_layout$color[j] &lt;- c(&quot;maroon&quot;,&quot;blue&quot;,&quot;orange&quot;)[i]
  }</code></pre>
<p>Ok, here’s the full modified <code>upset()</code> function.</p>
<pre><code>## Modified internal upset() code

startend &lt;- UpSetR:::FindStartEnd(data)
  first.col &lt;- startend[1]
  last.col &lt;- startend[2]

  if(color.pal == 1){
    palette &lt;- c(&quot;#1F77B4&quot;, &quot;#FF7F0E&quot;, &quot;#2CA02C&quot;, &quot;#D62728&quot;, &quot;#9467BD&quot;, &quot;#8C564B&quot;, &quot;#E377C2&quot;,
                 &quot;#7F7F7F&quot;, &quot;#BCBD22&quot;, &quot;#17BECF&quot;)
  } else{
    palette &lt;- c(&quot;#E69F00&quot;, &quot;#56B4E9&quot;, &quot;#009E73&quot;, &quot;#F0E442&quot;, &quot;#0072B2&quot;, &quot;#D55E00&quot;,
                 &quot;#CC79A7&quot;)
  }

  if(is.null(intersections) == F){
    Set_names &lt;- unique((unlist(intersections)))
    Sets_to_remove &lt;- UpSetR:::Remove(data, first.col, last.col, Set_names)
    New_data &lt;- UpSetR:::Wanted(data, Sets_to_remove)
    Num_of_set &lt;- UpSetR:::Number_of_sets(Set_names)
    if(keep.order == F){
      Set_names &lt;- UpSetR:::order_sets(New_data, Set_names)
    }
    All_Freqs &lt;- UpSetR:::specific_intersections(data, first.col, last.col, intersections, order.by, group.by, decreasing,
                                        cutoff, main.bar.color, Set_names)
  } else if(is.null(intersections) == T){
    Set_names &lt;- sets
    if(is.null(Set_names) == T || length(Set_names) == 0 ){
      Set_names &lt;- UpSetR:::FindMostFreq(data, first.col, last.col, nsets)
    }
    Sets_to_remove &lt;- UpSetR:::Remove(data, first.col, last.col, Set_names)
    New_data &lt;- UpSetR:::Wanted(data, Sets_to_remove)
    Num_of_set &lt;- UpSetR:::Number_of_sets(Set_names)
    if(keep.order == F){
    Set_names &lt;- UpSetR:::order_sets(New_data, Set_names)
    }
    All_Freqs &lt;- UpSetR:::Counter(New_data, Num_of_set, first.col, Set_names, nintersects, main.bar.color,
                         order.by, group.by, cutoff, empty.intersections, decreasing)
  }
  Matrix_setup &lt;- UpSetR:::Create_matrix(All_Freqs)
  labels &lt;- UpSetR:::Make_labels(Matrix_setup)
  #Chose NA to represent NULL case as result of NA being inserted when at least one contained both x and y
  #i.e. if one custom plot had both x and y, and others had only x, the y's for the other plots were NA
  #if I decided to make the NULL case (all x and no y, or vice versa), there would have been alot more if/else statements
  #NA can be indexed so that we still get the non NA y aesthetics on correct plot. NULL cant be indexed.
  att.x &lt;- c(); att.y &lt;- c();
  if(is.null(attribute.plots) == F){
    for(i in seq_along(attribute.plots$plots)){
      if(length(attribute.plots$plots[[i]]$x) != 0){
        att.x[i] &lt;- attribute.plots$plots[[i]]$x
      }
      else if(length(attribute.plots$plots[[i]]$x) == 0){
        att.x[i] &lt;- NA
      }
      if(length(attribute.plots$plots[[i]]$y) != 0){
        att.y[i] &lt;- attribute.plots$plots[[i]]$y
      }
      else if(length(attribute.plots$plots[[i]]$y) == 0){
        att.y[i] &lt;- NA
      }
    }
  }

  BoxPlots &lt;- NULL
  if(is.null(boxplot.summary) == F){
    BoxData &lt;- UpSetR:::IntersectionBoxPlot(All_Freqs, New_data, first.col, Set_names)
    BoxPlots &lt;- list()
    for(i in seq_along(boxplot.summary)){
      BoxPlots[[i]] &lt;- UpSetR:::BoxPlotsPlot(BoxData, boxplot.summary[i], att.color)
    }
  }

  customAttDat &lt;- NULL
  customQBar &lt;- NULL
  Intersection &lt;- NULL
  Element &lt;- NULL
  legend &lt;- NULL
  EBar_data &lt;- NULL
  if(is.null(queries) == F){
    custom.queries &lt;- UpSetR:::SeperateQueries(queries, 2, palette)
    customDat &lt;- UpSetR:::customQueries(New_data, custom.queries, Set_names)
    legend &lt;- UpSetR:::GuideGenerator(queries, palette)
    legend &lt;- UpSetR:::Make_legend(legend)
    if(is.null(att.x) == F &amp;&amp; is.null(customDat) == F){
      customAttDat &lt;- UpSetR:::CustomAttData(customDat, Set_names)
    }
    customQBar &lt;- UpSetR:::customQueriesBar(customDat, Set_names, All_Freqs, custom.queries)
  }
  if(is.null(queries) == F){
    Intersection &lt;- UpSetR:::SeperateQueries(queries, 1, palette)
    Matrix_col &lt;- UpSetR:::intersects(QuerieInterData, Intersection, New_data, first.col, Num_of_set,
                             All_Freqs, expression, Set_names, palette)
    Element &lt;- UpSetR:::SeperateQueries(queries, 1, palette)
    EBar_data &lt;-UpSetR:::ElemBarDat(Element, New_data, first.col, expression, Set_names,palette, All_Freqs)
  } else{
    Matrix_col &lt;- NULL
  }
  
  Matrix_layout &lt;- UpSetR:::Create_layout(Matrix_setup, matrix.color, Matrix_col, matrix.dot.alpha)</code></pre>
<p>As a little pause in <code>upset()</code>, let’s check what actually <code>Matrix_layout</code> looks.</p>
<pre><code>Matrix_layout</code></pre>
<pre><code>##    y x value  color alpha Intersection
## 1  1 1     1   blue   1.0         1yes
## 2  2 1     1   blue   1.0         1yes
## 3  3 1     1   blue   1.0         1yes
## 4  1 2     0 gray83   0.5          4No
## 5  2 2     1   blue   1.0         2yes
## 6  3 2     1   blue   1.0         2yes
## 7  1 3     1   blue   1.0         3yes
## 8  2 3     0 gray83   0.5          8No
## 9  3 3     1   blue   1.0         3yes
## 10 1 4     1   blue   1.0         4yes
## 11 2 4     1   blue   1.0         4yes
## 12 3 4     0 gray83   0.5         12No
## 13 1 5     0 gray83   0.5         13No
## 14 2 5     0 gray83   0.5         14No
## 15 3 5     1   blue   1.0         5yes
## 16 1 6     0 gray83   0.5         16No
## 17 2 6     1   blue   1.0         6yes
## 18 3 6     0 gray83   0.5         18No
## 19 1 7     1   blue   1.0         7yes
## 20 2 7     0 gray83   0.5         20No
## 21 3 7     0 gray83   0.5         21No</code></pre>
<p>We figured out that we had to change the colors only the rows with <code>value = 1</code> and that <code>y</code> was the row grouping variable.</p>
<pre><code>## our modification
  for(i in 1:3) {
      j &lt;- which(Matrix_layout$y == i &amp; Matrix_layout$value == 1)
      if(length(j) > 0) Matrix_layout$color[j] &lt;- c(&quot;maroon&quot;,&quot;blue&quot;,&quot;orange&quot;)[i]
  }</code></pre>
<p>Here’s our modified <code>Matrix_layout</code>:</p>
<pre><code>Matrix_layout</code></pre>
<pre><code>##    y x value  color alpha Intersection
## 1  1 1     1 maroon   1.0         1yes
## 2  2 1     1   blue   1.0         1yes
## 3  3 1     1 orange   1.0         1yes
## 4  1 2     0 gray83   0.5          4No
## 5  2 2     1   blue   1.0         2yes
## 6  3 2     1 orange   1.0         2yes
## 7  1 3     1 maroon   1.0         3yes
## 8  2 3     0 gray83   0.5          8No
## 9  3 3     1 orange   1.0         3yes
## 10 1 4     1 maroon   1.0         4yes
## 11 2 4     1   blue   1.0         4yes
## 12 3 4     0 gray83   0.5         12No
## 13 1 5     0 gray83   0.5         13No
## 14 2 5     0 gray83   0.5         14No
## 15 3 5     1 orange   1.0         5yes
## 16 1 6     0 gray83   0.5         16No
## 17 2 6     1   blue   1.0         6yes
## 18 3 6     0 gray83   0.5         18No
## 19 1 7     1 maroon   1.0         7yes
## 20 2 7     0 gray83   0.5         20No
## 21 3 7     0 gray83   0.5         21No</code></pre>
<p>Ok, let’s continue with the rest of <code>upset()</code>.</p>
<pre><code>## continuing with upset()
  
  Set_sizes &lt;- UpSetR:::FindSetFreqs(New_data, first.col, Num_of_set, Set_names, keep.order)
  Bar_Q &lt;- NULL
  if(is.null(queries) == F){
    Bar_Q &lt;- UpSetR:::intersects(QuerieInterBar, Intersection, New_data, first.col, Num_of_set, All_Freqs, expression, Set_names, palette)
  }
  QInter_att_data &lt;- NULL
  QElem_att_data &lt;- NULL
  if((is.null(queries) == F) &amp; (is.null(att.x) == F)){
    QInter_att_data &lt;- UpSetR:::intersects(QuerieInterAtt, Intersection, New_data, first.col, Num_of_set, att.x, att.y,
                                  expression, Set_names, palette)
    QElem_att_data &lt;- UpSetR:::elements(QuerieElemAtt, Element, New_data, first.col, expression, Set_names, att.x, att.y,
                               palette)
  }
  AllQueryData &lt;- UpSetR:::combineQueriesData(QInter_att_data, QElem_att_data, customAttDat, att.x, att.y)

  ShadingData &lt;- NULL

  if(is.null(set.metadata) == F){
    ShadingData &lt;- get_shade_groups(set.metadata, Set_names, Matrix_layout, shade.alpha)
    output &lt;- Make_set_metadata_plot(set.metadata, Set_names)
    set.metadata.plots &lt;- output[[1]]
    set.metadata &lt;- output[[2]]

    if(is.null(ShadingData) == FALSE){
    shade.alpha &lt;- unique(ShadingData$alpha)
    }
  } else {
    set.metadata.plots &lt;- NULL
  }
  if(is.null(ShadingData) == TRUE){
  ShadingData &lt;- UpSetR:::MakeShading(Matrix_layout, shade.color)
  }
  Main_bar &lt;- suppressMessages(UpSetR:::Make_main_bar(All_Freqs, Bar_Q, show.numbers, mb.ratio, customQBar, number.angles, EBar_data, mainbar.y.label,
                            mainbar.y.max, scale.intersections, text.scale, attribute.plots))
  Matrix &lt;- UpSetR:::Make_matrix_plot(Matrix_layout, Set_sizes, All_Freqs, point.size, line.size,
                             text.scale, labels, ShadingData, shade.alpha)
  Sizes &lt;- UpSetR:::Make_size_plot(Set_sizes, sets.bar.color, mb.ratio, sets.x.label, scale.sets, text.scale, set_size.angles,set_size.show)

  # Make_base_plot(Main_bar, Matrix, Sizes, labels, mb.ratio, att.x, att.y, New_data,
  #                expression, att.pos, first.col, att.color, AllQueryData, attribute.plots,
  #                legend, query.legend, BoxPlots, Set_names, set.metadata, set.metadata.plots)

  structure(class = &quot;upset&quot;,
    .Data=list(
      Main_bar = Main_bar,
      Matrix = Matrix,
      Sizes = Sizes,
      labels = labels,
      mb.ratio = mb.ratio,
      att.x = att.x,
      att.y = att.y,
      New_data = New_data,
      expression = expression,
      att.pos = att.pos,
      first.col = first.col,
      att.color = att.color,
      AllQueryData = AllQueryData,
      attribute.plots = attribute.plots,
      legend = legend,
      query.legend = query.legend,
      BoxPlots = BoxPlots,
      Set_names = Set_names,
      set.metadata = set.metadata,
      set.metadata.plots = set.metadata.plots)
  )</code></pre>
<p><img src="https://i1.wp.com/lieberinstitute.github.io/rstatsclub/post/2018-07-27-hacking-our-way-through-upsetr_files/figure-html/unnamed-chunk-11-1.png?w=450" data-recalc-dims="1"></p>
</div>
<div>
<h3>Line colors</h3>
<p>Ok, that’s great but we have a problem with the lines. The color is no longer black, so we went deeper into the rabbit hole and found that the internal <code>Make_matrix_plot()</code> function is where the lines are made. We made some edits but got a plot where the lines were on top of the circles as shown in this screenshot.</p>
<div>
<img src="https://i2.wp.com/lieberinstitute.github.io/rstatsclub/post/2018-07-27-hacking-our-way-through-upsetr_files/Screen%20Shot%202018-07-27%20at%2012.17.58%20PM.png?w=450" data-recalc-dims="1">
</div>
<p>Our club session was out of time, so we decided to continue our project another day and ask for help on twitter. And yay, we got help super fast!</p>
<blockquote class="twitter-tweet">
<p lang="en" dir="ltr">Thank you and <a rel="nofollow" href="https://twitter.com/thatdnaguy?ref_src=twsrc%5Etfw" target="_blank">@thatdnaguy</a>, that did it! <a rel="nofollow" href="https://t.co/tzQvhKFXgR" target="_blank">pic.twitter.com/tzQvhKFXgR</a></p>
<p>— LIBD rstats club (@LIBDrstats) <a rel="nofollow" href="https://twitter.com/LIBDrstats/status/1022903971416088577?ref_src=twsrc%5Etfw" target="_blank">July 27, 2018</a></p></blockquote>
<p></p>
<p>So here’s our modified version of <code>Make_matrix_plot()</code> that keeps the lines black.</p>
<pre><code>Make_matrix_plot &lt;- function(Mat_data,Set_size_data, Main_bar_data, point_size, line_size, text_scale, labels,
                             shading_data, shade_alpha){

  if(length(text_scale) == 1){
    name_size_scale &lt;- text_scale
  }
  if(length(text_scale) > 1 &amp;&amp; length(text_scale) &lt;= 6){
    name_size_scale &lt;- text_scale[5]
  }
  
  Mat_data$line_col &lt;- 'black'

  Matrix_plot &lt;- (ggplot()
                  + theme(panel.background = element_rect(fill = &quot;white&quot;),
                          plot.margin=unit(c(-0.2,0.5,0.5,0.5), &quot;lines&quot;),
                          axis.text.x = element_blank(),
                          axis.ticks.x = element_blank(),
                          axis.ticks.y = element_blank(),
                          axis.text.y = element_text(colour = &quot;gray0&quot;,
                                                     size = 7*name_size_scale, hjust = 0.4),
                          panel.grid.major = element_blank(),
                          panel.grid.minor = element_blank())
                  + xlab(NULL) + ylab(&quot;   &quot;)
                  + scale_y_continuous(breaks = c(1:nrow(Set_size_data)),
                                       limits = c(0.5,(nrow(Set_size_data) +0.5)),
                                       labels = labels, expand = c(0,0))
                  + scale_x_continuous(limits = c(0,(nrow(Main_bar_data)+1 )), expand = c(0,0))
                  + geom_rect(data = shading_data, aes_string(xmin = &quot;min&quot;, xmax = &quot;max&quot;,
                                                              ymin = &quot;y_min&quot;, ymax = &quot;y_max&quot;),
                              fill = shading_data$shade_color, alpha = shade_alpha)
                  + geom_line(data= Mat_data, aes_string(group = &quot;Intersection&quot;, x=&quot;x&quot;, y=&quot;y&quot;,
                                                         colour = &quot;line_col&quot;), size = line_size)
                 + geom_point(data= Mat_data, aes_string(x= &quot;x&quot;, y= &quot;y&quot;), colour = Mat_data$color,
                     size= point_size, alpha = Mat_data$alpha, shape=16)
                  + scale_color_identity())
  Matrix_plot &lt;- ggplot_gtable(ggplot_build(Matrix_plot))
  return(Matrix_plot)
}</code></pre>
<p>Using that modified version we can then run the code again (note that we are not using <code>UpSetR:::</code> before <code>Make_matrix_plot</code>) and get the plot we wanted.</p>
<pre><code>Matrix &lt;- Make_matrix_plot(Matrix_layout, Set_sizes, All_Freqs, point.size, line.size,
                             text.scale, labels, ShadingData, shade.alpha)
  Sizes &lt;- UpSetR:::Make_size_plot(Set_sizes, sets.bar.color, mb.ratio, sets.x.label, scale.sets, text.scale, set_size.angles,set_size.show)

  # Make_base_plot(Main_bar, Matrix, Sizes, labels, mb.ratio, att.x, att.y, New_data,
  #                expression, att.pos, first.col, att.color, AllQueryData, attribute.plots,
  #                legend, query.legend, BoxPlots, Set_names, set.metadata, set.metadata.plots)

  structure(class = &quot;upset&quot;,
    .Data=list(
      Main_bar = Main_bar,
      Matrix = Matrix,
      Sizes = Sizes,
      labels = labels,
      mb.ratio = mb.ratio,
      att.x = att.x,
      att.y = att.y,
      New_data = New_data,
      expression = expression,
      att.pos = att.pos,
      first.col = first.col,
      att.color = att.color,
      AllQueryData = AllQueryData,
      attribute.plots = attribute.plots,
      legend = legend,
      query.legend = query.legend,
      BoxPlots = BoxPlots,
      Set_names = Set_names,
      set.metadata = set.metadata,
      set.metadata.plots = set.metadata.plots)
  )</code></pre>
<p><img src="https://i2.wp.com/lieberinstitute.github.io/rstatsclub/post/2018-07-27-hacking-our-way-through-upsetr_files/figure-html/unnamed-chunk-13-1.png?w=450" data-recalc-dims="1"></p>
<p>We have quite a bit more to do in order to complete our pull request. We are also curious if you would have used a different approach to hack your way through <em><a rel="nofollow" href="https://cran.r-project.org/package=UpSetR" target="_blank">UpSetR</a></em> (<a rel="nofollow" href="http://github.com/hms-dbmi/UpSetR" target="_blank">Gehlenborg, 2016</a>). For example, maybe some functions from <em><a rel="nofollow" href="https://cran.r-project.org/package=devtools" target="_blank">devtools</a></em> <a></a>(<a rel="nofollow" href="https://cran.r-project.org/package=devtools" target="_blank">Wickham, Hester, and Chang, 2018</a>) would have enabled to do this equally fast without having to introduce <code>UpSetR:::</code> calls.</p>
<p>Thanks for reading!</p>
</div>
<div>
<h3>Acknowledgements</h3>
<p>This blog post was made possible thanks to:</p>
<ul>
<li><em><a rel="nofollow" href="http://bioconductor.org/packages/BiocStyle" target="_blank">BiocStyle</a></em> <a></a>(<a rel="nofollow" href="https://github.com/Bioconductor/BiocStyle" target="_blank">Oleś, Morgan, and Huber, 2018</a>)</li>
<li><em><a rel="nofollow" href="https://cran.r-project.org/package=blogdown" target="_blank">blogdown</a></em> <a></a>(<a rel="nofollow" href="https://github.com/rstudio/blogdown" target="_blank">Xie, Hill, and Thomas, 2017</a>)</li>
<li><em><a rel="nofollow" href="https://cran.r-project.org/package=devtools" target="_blank">devtools</a></em> (<a rel="nofollow" href="https://cran.r-project.org/package=devtools" target="_blank">Wickham, Hester, and Chang, 2018</a>)</li>
<li><em><a rel="nofollow" href="https://cran.r-project.org/package=knitcitations" target="_blank">knitcitations</a></em> <a></a>(<a rel="nofollow" href="https://cran.r-project.org/package=knitcitations" target="_blank">Boettiger, 2017</a>)</li>
</ul>
</div>
<div>
<h3>References</h3>
<p>
<a></a><a rel="nofollow" href="http://feedproxy.google.com/~r/LIBDrstats/~3/8ZYTyu4yFIE/#cite-Boettiger_2017" target="_blank">[1]</a><cite> C. Boettiger. <em>knitcitations: Citations for ‘Knitr’ Markdown Files</em>. R package version 1.0.8. 2017. URL: <a rel="nofollow" href="https://cran.r-project.org/package=knitcitations" target="_blank">https://CRAN.R-project.org/package=knitcitations</a>.</cite>
</p>
<p>
<a></a><a rel="nofollow" href="http://feedproxy.google.com/~r/LIBDrstats/~3/8ZYTyu4yFIE/#cite-Gehlenborg_2016" target="_blank">[2]</a><cite> N. Gehlenborg. <em>UpSetR: A More Scalable Alternative to Venn and Euler Diagrams for Visualizing Intersecting Sets</em>. R package version 1.4.0. 2016. URL: <a rel="nofollow" href="http://github.com/hms-dbmi/UpSetR" target="_blank">http://github.com/hms-dbmi/UpSetR</a>.</cite>
</p>
<p>
<a></a><a rel="nofollow" href="http://feedproxy.google.com/~r/LIBDrstats/~3/8ZYTyu4yFIE/#cite-Oles_2018" target="_blank">[3]</a><cite> A. Oleś, M. Morgan and W. Huber. <em>BiocStyle: Standard styles for vignettes and other Bioconductor documents</em>. R package version 2.8.2. 2018. URL: <a rel="nofollow" href="https://github.com/Bioconductor/BiocStyle" target="_blank">https://github.com/Bioconductor/BiocStyle</a>.</cite>
</p>
<p>
<a></a><a rel="nofollow" href="http://feedproxy.google.com/~r/LIBDrstats/~3/8ZYTyu4yFIE/#cite-Wickham_2018" target="_blank">[4]</a><cite> H. Wickham, J. Hester and W. Chang. <em>devtools: Tools to Make Developing R Packages Easier</em>. R package version 1.13.6. 2018. URL: <a rel="nofollow" href="https://cran.r-project.org/package=devtools" target="_blank">https://CRAN.R-project.org/package=devtools</a>.</cite>
</p>
<p>
<a></a><a rel="nofollow" href="http://feedproxy.google.com/~r/LIBDrstats/~3/8ZYTyu4yFIE/#cite-Xie_2017" target="_blank">[5]</a><cite> Y. Xie, A. P. Hill and A. Thomas. <em>blogdown: Creating Websites with R Markdown</em>. ISBN 978-0815363729. Boca Raton, Florida: Chapman and Hall/CRC, 2017. URL: <a rel="nofollow" href="https://github.com/rstudio/blogdown" target="_blank">https://github.com/rstudio/blogdown</a>.</cite>
</p>
</div>
<div>
<h3>Reproducibility</h3>
<pre><code>## Session info ----------------------------------------------------------------------------------------------------------</code></pre>
<pre><code>##  setting  value                       
##  version  R version 3.5.1 (2018-07-02)
##  system   x86_64, darwin15.6.0        
##  ui       X11                         
##  language (EN)                        
##  collate  en_US.UTF-8                 
##  tz       America/New_York            
##  date     2018-07-27</code></pre>
<pre><code>## Packages --------------------------------------------------------------------------------------------------------------</code></pre>
<pre><code>##  package       * version date       source                            
##  assertthat      0.2.0   2017-04-11 cran (@0.2.0)                     
##  backports       1.1.2   2017-12-13 cran (@1.1.2)                     
##  base          * 3.5.1   2018-07-05 local                             
##  bibtex          0.4.2   2017-06-30 CRAN (R 3.5.0)                    
##  bindr           0.1.1   2018-03-13 cran (@0.1.1)                     
##  bindrcpp        0.2.2   2018-03-29 cran (@0.2.2)                     
##  BiocStyle     * 2.8.2   2018-05-30 Bioconductor                      
##  blogdown        0.8     2018-07-15 CRAN (R 3.5.0)                    
##  bookdown        0.7     2018-02-18 CRAN (R 3.5.0)                    
##  colorout      * 1.2-0   2018-05-03 Github (jalvesaq/colorout@c42088d)
##  colorspace      1.3-2   2016-12-14 cran (@1.3-2)                     
##  compiler        3.5.1   2018-07-05 local                             
##  crayon          1.3.4   2017-09-16 cran (@1.3.4)                     
##  datasets      * 3.5.1   2018-07-05 local                             
##  devtools      * 1.13.6  2018-06-27 cran (@1.13.6)                    
##  digest          0.6.15  2018-01-28 CRAN (R 3.5.0)                    
##  dplyr           0.7.6   2018-06-29 CRAN (R 3.5.1)                    
##  evaluate        0.11    2018-07-17 CRAN (R 3.5.0)                    
##  ggplot2       * 3.0.0   2018-07-03 CRAN (R 3.5.0)                    
##  glue            1.3.0   2018-07-17 CRAN (R 3.5.0)                    
##  graphics      * 3.5.1   2018-07-05 local                             
##  grDevices     * 3.5.1   2018-07-05 local                             
##  grid          * 3.5.1   2018-07-05 local                             
##  gridExtra     * 2.3     2017-09-09 CRAN (R 3.5.0)                    
##  gtable          0.2.0   2016-02-26 CRAN (R 3.5.0)                    
##  htmltools       0.3.6   2017-04-28 cran (@0.3.6)                     
##  httr            1.3.1   2017-08-20 CRAN (R 3.5.0)                    
##  jsonlite        1.5     2017-06-01 CRAN (R 3.5.0)                    
##  knitcitations * 1.0.8   2017-07-04 CRAN (R 3.5.0)                    
##  knitr           1.20    2018-02-20 cran (@1.20)                      
##  labeling        0.3     2014-08-23 cran (@0.3)                       
##  lazyeval        0.2.1   2017-10-29 CRAN (R 3.5.0)                    
##  lubridate       1.7.4   2018-04-11 CRAN (R 3.5.0)                    
##  magrittr        1.5     2014-11-22 cran (@1.5)                       
##  memoise         1.1.0   2017-04-21 CRAN (R 3.5.0)                    
##  methods       * 3.5.1   2018-07-05 local                             
##  munsell         0.5.0   2018-06-12 CRAN (R 3.5.0)                    
##  pillar          1.3.0   2018-07-14 CRAN (R 3.5.0)                    
##  pkgconfig       2.0.1   2017-03-21 cran (@2.0.1)                     
##  plyr          * 1.8.4   2016-06-08 cran (@1.8.4)                     
##  purrr           0.2.5   2018-05-29 cran (@0.2.5)                     
##  R6              2.2.2   2017-06-17 CRAN (R 3.5.0)                    
##  Rcpp            0.12.18 2018-07-23 CRAN (R 3.5.1)                    
##  RefManageR      1.2.0   2018-04-25 CRAN (R 3.5.0)                    
##  rlang           0.2.1   2018-05-30 cran (@0.2.1)                     
##  rmarkdown       1.10    2018-06-11 CRAN (R 3.5.0)                    
##  rprojroot       1.3-2   2018-01-03 cran (@1.3-2)                     
##  scales          0.5.0   2017-08-24 cran (@0.5.0)                     
##  stats         * 3.5.1   2018-07-05 local                             
##  stringi         1.2.4   2018-07-20 CRAN (R 3.5.0)                    
##  stringr         1.3.1   2018-05-10 CRAN (R 3.5.0)                    
##  tibble          1.4.2   2018-01-22 cran (@1.4.2)                     
##  tidyselect      0.2.4   2018-02-26 cran (@0.2.4)                     
##  tools           3.5.1   2018-07-05 local                             
##  UpSetR        * 1.4.0   2018-07-27 Github (hms-dbmi/UpSetR@fe2812c)  
##  utils         * 3.5.1   2018-07-05 local                             
##  withr           2.1.2   2018-03-15 CRAN (R 3.5.0)                    
##  xfun            0.3     2018-07-06 CRAN (R 3.5.0)                    
##  xml2            1.2.0   2018-01-24 CRAN (R 3.5.0)                    
##  yaml            2.1.19  2018-05-01 CRAN (R 3.5.0)</code></pre>
</div>
<p><img width="1" alt="" src="http://feeds.feedburner.com/~r/LIBDrstats/~4/8ZYTyu4yFIE" height="1"></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://feedproxy.google.com/~r/LIBDrstats/~3/8ZYTyu4yFIE/"> Rstats on LIBD rstats club</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/54MKLE4ut-g" height="1"></a></div>