Hey guys, in this video I wanted to talk about a data visualization called an UpSet plot. I have an
example UpSet plot here and an UpSet plot is used basically as an alternative to a Venn diagram and
it's usually used as an alternative where you have many sets. Instead of having a busy diagram like
this, it's become more common to use something called an UpSet plot. In this video, I wanted to
talk about how you can read an UpSet plot and then I have a short R demo for how you can create an
UpSet plot in R that I will talk about afterwards. So let's go ahead and get started with the video.
I found this sample dataset online and I'll put a link in the description box below
to this Venn diagram, but as you can see this is a Venn diagram that has four sets. It has A, B, C,
D, and then it has data that can belong to any of the sets. For example, 50--in this case this was
like sampled genes--and so in this case, there are 50 genes that just belong to set A; there are 144
that just belong to set B; but then you can also have sets or genes that belong to multiple sets.
For example, 46 is the sample size that belongs to both A and B but not C and D. And then for
example you have sample data that belongs to A, B, C, and D, which is 24. So basically that's
how you read this type of Venn diagram and so it gives you set membership information
and like I said in the beginning of the video, it's been more common to visualize this type of
set information when you have many sets using an UpSet plot instead of a Venn diagram,
so this is the equivalent visualization using an UpSet plot for this same data and I will show
you how I created this data in R. How do you read this plot? This is what's called an UpSet plot and
you basically read the data as follows. You have your set information or your set membership
here, so you have A, D, C, B and this I ordered it in terms of frequency but you can change that
or customize that as well. And then the dots and the lines here represent the set membership. For
example, you have some data that just exists in set A, B, C, and D, and that would be represented
just by the dots. For example, for the sample genes that just exist in a set A that would
correspond to this column here because it has just a dot membership in A and then the sample size is
given as a bar graph on top of this portion of the visualization. Here we see that the sample
size for samples that just exist in set A is 50 and then if we go back up to the Venn diagram
we see that that is correct, so that's how you would read just the dots. We have A, B, C,
D here and then for the line segments that have the dots with the lines connected to them
that is for intersections. For example, if we look at the last column here this is for the
samples that have membership in A, D, C, and B. We know that because the dots for A, B, C, and D
are filled in and the lines are connecting them as well and it says here that the sample size is 24
and again we know that that's true from looking at the Venn diagram. Then on the left hand side here,
we also have just the set information and since I ordered by frequencies, we can also get that
just from the order. So we see that set B has the largest sample size then C, then D, then A.
We see that both in the bar graph and also in the ordering of the bar graph and so that's basically
how you read an UpSet plot. In the next section, I'll show how you can create this plot in R. Okay,
so I switched to an R window. This tutorial is going to be very short but basically to plot an
UpSet plot in R, you have to have a package called UpSetR installed. I already installed that package
so I'm just going to load it in using library and then this line of code I got from a website for
the Venn diagram. This is the website and I'll put the link in the description box below and that's
the sample data that they used to create the Venn diagram. This is actually a tutorial for creating
Venn diagrams in R. If I run this line of code from that page, it gives me a list object that
has all the sample data that I'm going to use to create the UpSet plot instead of the Venn diagram.
Running this next line of codes just gives me the same exact data as in the Venn diagram and so it's
a list object and it's a list of four vectors. Every vector is a set and it has the names here A,
B, C, D like we just showed before. To create an UpSet plot, I'm going to use this list object. If
you're creating this type of data or loading in this type of data from scratch, one way to create
an UpSet plot is you want to create the data as a list of vectors where your vectors are your sets,
and since I already have that loaded in as x, the line of code to create an UpSet plot is just
one line. So there's a function UpSet that will create the data visualization and then fromlist
is also a function from UpSetR and fromlist you just pass in the name of your list object
and then optionally I put order by to give you the decreasing frequencies. So running this line of
code gives me the data visualization again ordered by frequency and so there are customizations that
you can do to this. For example, you can add color to certain sets that you want to emphasize but
this is the basic way to create an UpSet plot in R and that's it for this video. *chiptune music*