New to Us Chart Types Video Lecture Transcript
This transcript was automatically generated by Zoom, so there may be discrepancies between the video and the text.
16:41:58 Hi! Everybody! Welcome back in this video. We're gonna go ahead and learn some chart types that are new to us, that plot only enables us to create.
16:42:08 So in the past who talked a lot about like bar charts, histogram scanner ponds, line charts.
16:42:14 So these are all really great and useful, and this I figured we could introduce a couple of chart types that plotly enables us to quickly make to quickly make that would have been more difficult to make, and things like Matt Plot lib or Seborn or Boca so You'll notice that
16:42:28 We're importing both. Plotley Express as well as just the straight graph object.
16:42:33 So we're going to use both of these in this notebook.
16:42:36 And I'll make sure it's clear when we use which one.
16:42:39 So the first chart type we're gonna learn about is a waterfall chart.
16:42:42 So waterfall charts are a way for us to track a series of additions and subtractions to a running total.
16:42:50 And so this is useful, for instance, in like financial applications, where maybe you're trying to keep track of a running, checking balance or savings account balance, etc.
16:43:00 And basically you're going to keep track of when you make a deposit or or withdraw.
16:43:05 So in this sort of waterfall, chart rectangles represent changes, additions, or subtractions from the total.
16:43:14 So, for instance, maybe we have this example chart that might be useful to zoom in on.
16:43:18 Well, apparently keeps me getting some more, anyway. So let's say that at the beginning of some quarter we start with $0 for our revenue or whatever, and so maybe sales takes in $60.
16:43:33 So that moves the Z 0 up 60. So the height of the rectangle is 60, and it goes up from the running total of 0, and then consulting.
16:43:44 Maybe they bring in $80. So we go over from 60, and then this rectangle is 80 units tall, and we go up because it's an addition.
16:43:52 And then we just want to point out all right. So what's our running net revenue?
16:43:57 It's 140. So that's what the blue total total height rectangle represents.
16:44:02 Then we want to make keep track of the spending that we did in that quarter.
16:44:08 So we subtracted 40. So we went down 40, and now the we need to note that the height of the the running, the rectangle goes down, indicating a subtraction, and then maybe we had some other various expenses that each of them on their own was pretty small but
16:44:27 Altogether they took about $20. So again, we're going down.
16:44:29 So the bottom of the rectangle goes our running total, and then by the end of it, we just keep track of going again from the bottom up to the top.
16:44:37 What's our total now? It's $80. So that's how waterfall chart works.
16:44:43 They call it a waterfall chart, probably because it maybe looks like a series of waterfalls.
16:44:47 Basically the idea is we take a total. And then we keep track of additions and subtractions from that total using rectangles where, if it's in addition, the top of the next rectangle represents what the total is after the transaction or the addition and then if it's a
16:45:04 Subtraction, the bottom of the rectangle represents where the total is after that rectangle has been drawn, so you can make one of these.
16:45:15 This is one of the instances where you can't use plot.
16:45:19 We express, you just have to use the graphical objects.
16:45:23 So in order to do that, you go ahead and you call go, which is graph objects.
16:45:28 Waterfall, and so then the waterfall needs a number of things.
16:45:33 The first thing you want to put in is the orientation.
16:45:36 So this is a vertical waterfall chart
16:45:40 Another option is, you can have horizontal or just imagine rotating this.
16:45:46 So vertical is the default, so in our example we won't have that argument.
16:45:51 The next thing you need to do is provide an array or a tuple, or a list of route of measures, and so measure.
16:46:00 Meaning is the is the next rectangle being plotted relative meaning.
16:46:04 It's going to be an addition or subtraction, or is it total meaning?
16:46:09 You want to draw the running total. So, for instance, the greens in the red.
16:46:15 So if we go in series relative rectangle, relevant rectangle, total rectangle, relative rectangular relative rectangle, total rectangle.
16:46:25 The next is you need to put in arguments for the X and the Y.
16:46:32 So the vertical and horizontal axes.
16:46:34 So, if your orientation is vertical, X. Would take in an array of rectangle changes, and if your orientation was horizontal, you'd put in labels, sorry I had that backwards.
16:46:49 If your orientation is vertical, X takes in an array of labels, and if you're orientation is horizontal.
16:46:55 That's takes in an array of changes. And then, why, it's flip-flop.
16:46:59 So if it's horizontal, you put in labels, and if it's a vertical you put in the chain changes, and then finally, texts, you can provide text.
16:47:09 If you'd like to see things written on the rectangles like plus 60 plus 80, etc.
16:47:14 So in this example our men are given, it's just going to create this exact same plot.
16:47:20 So the measures are given as I described them before, relative, relative, total, relative, relative total, because we're going with the default.
16:47:29 Our orientation is vertical, so the X gets a list of labels, and then for our line we put in a a series of changes.
16:47:43 So the first 2 are plus 60 plus 80. So that's why we have that.
16:47:47 Because it's a total rectangle. Now it's got to be 0.
16:47:51 Then the next 2, or minus 40 and minus 20, and then again we end with a running total rectangle, which was 0
16:47:59 Okay. And now you can see we have that chart
16:48:04 That we produced above so if you'd like to learn more about the arguments for this trace, you can check out either the tutorial or the documentation page for the Api reference.
16:48:19 Another chart type that gets used a lot in business are funnel plots.
16:48:24 So funnel plots, keeps track of the number of items over a series of stages, and so I think a decent example for this is if you think about trying to keep track of the number of people over the course of the advertising.
16:48:40 For maybe an application like a phone app so you're on your phone app, you see, an advertisement saved for like, let's say you're playing candy crush.
16:48:49 You see, an advertisement for an insurance company.
16:48:51 Maybe you click on that advertisement, and then maybe, after clicking on the advertisement, you go ahead and get a policy with them, or you download their app.
16:49:00 So, keeping track of the number of people you can, the company will know how many people they advertise to.
16:49:06 Let's say that that's a 100, and then after that they'll be able to tell through whatever company they're working with.
16:49:11 How many of those 100 clicked on it. So let's say, that's 40, and then they can go ahead and tell of those 40 people that clicked on it.
16:49:19 How many of them downloaded and signed up for the app, which was 10.
16:49:23 So to make one of these, you use the Potley express function called Px.
16:49:28 Dot funnel, and so we're gonna use a data dictionary for this.
16:49:33 So for this data dictionary, it's got 100, and then the numbers of individuals like 140 and 10, and then the labels of the stages.
16:49:43 So, for instance, on add clicked on the AD downloaded the Adm.
16:49:46 So when you make the funnel chart you to call Px dot funnel, you put in your data, you put in.
16:49:52 If you want a horizontal one so like it just tracks them horizontally.
16:49:57 You put in the numbers as the horizontal axis and the labels as the vertical axis. Sorry.
16:50:05 So this one they convert a culture. I keep flipping, vertical and horizontal, so let me just run it so if we make our horizontal, I'm variables the number.
16:50:14 It's going to set the width of the rectangles, and if we set our vertical to the labels that will go ahead and set the stages, so this goes from the top to the bottom.
16:50:24 Story of soda. Yeah. Showing the funnel effect of this process.
16:50:28 So going from a 100 to 40 to 10 alternatively, we could make one that goes from left to right by just switching the X and the Y.
16:50:37 So now y is equal to the number which will give us the height of the rectangle, and x is equal to the stage hey?
16:50:44 So here's the horizontal one that goes from left to right.
16:50:49 There are additional aesthetic options that you can make for this.
16:50:53 So you could break the funnel up into subgroups, etc. I'm gonna leave.
16:50:58 It's you to check out those arguments by looking at the documentation.
16:51:02 Another chart tape that we haven't seen before is a sanctity diagram.
16:51:07 So these are kind of complicated. And I think trying to do it through the words alone is difficult.
16:51:11 So I'm going to go ahead and show you what a sinky diagram looks like.
16:51:14 So we're gonna go with this example. So Sankey diagrams are a way to show how different groups decompose into other groups.
16:51:23 So the example I've come up with here is, let's say you have 3 teams from 3 different nations.
16:51:29 So think of this maybe, like a world cup situation where you've got soccer team A from soccer team from nation and soccer team for Nation B and soccer team for Nation C, or maybe it's like Olympic basketball.
16:51:40 But one thing you'll know if you follow these is the the people who are on each of these national teams are not always necessarily born in those national teams.
16:51:52 So. There are, for instance, basketball players who maybe were born in a different country, but because they reside in the country they play, for they can play for that team.
16:52:01 So in this example, we can imagine that we have the teams on the left, and maybe we're interested in seeing how the birth countries for those teams break down into nation.
16:52:11 A nation, B nation, C, a, nation, d and so this is the San Diego where you can go ahead, and it will take the members from one group and then draw bands going into the different group.
16:52:25 So, for instance, this top band, which I'm now hovering over, indicates that there are 8 people from Nation A's team that were actually born in nation.
16:52:34 A. How do I know that? Well, I know that because the width or the height of the band going from the nation, a team over to Nation A is 8 high, which I can see from my hover tool similarly, I can go over this next one and see intonation B it's 3 high so that means there are 3 people
16:52:51 From nations, a team that were born from Nation B. And then you can also see another examples so there's one person from Nations A's team that was born in Nation C.
16:53:04 So the Wantley function for doing this is Go dot sanky.
16:53:09 So it's a graph object, not a plot. Lee. Express function.
16:53:11 You have to provide arguments like node, which takes in a dictionary of labels, and so the labels you provide are what's drawn next to these rectangles.
16:53:22 So for us. That's the nation, a team, the Nation B team, the Nation C team.
16:53:27 But you'll notice that these are provided as a list.
16:53:30 So the way that you need to keep track of them. Then for the links you sort of think of this like a network, is nation a team corresponds to the 0 entry of this list.
16:53:41 And so when I want to describe the bands going from the nation, a team to the other nations, you have to remember the source of that will be the index for the questioning band that you're interested in.
16:53:57 So if you're interested in the nation, B team, you would use a one.
16:54:00 If you're interested in the nation's C team, you'd use it, too.
16:54:02 If you want to go to Nation A, not the team, but just the nation.
16:54:06 You use a 4 or sorry, a 3, and so forth, and so the sources of this are where the thin these see through bands start, and then the targets are where they go.
16:54:18 So for instance, this first entry going from 0 to 3 has a weight of 8.
16:54:24 That's this band and then you can see the next entry has the source of 0, a target of 4 and a weight of 3.
16:54:31 Is this band if we go to the last one. So we start at 2, we go to 3, and we have a weight of one
16:54:38 That's this band. Okay, so that's how Sankey diagrams work.
16:54:43 These are useful for sort of seeing breakdowns of things like this, and sort of our sort of in vogue.
16:54:51 Graph type. So I see a lot of these being made online.
16:54:56 So I figured you might want to know how to make quantum and how they work the last chart type.
16:55:01 We're gonna see is Nora known as a sunburst chart.
16:55:04 So this is another way to look at the breakdown of a group into smaller groups.
16:55:10 So we're going to look at the tips data.
16:55:13 So we learned about this a while ago, I think back in the
16:55:18 Seborn notebooks. So each row gives a bill, a tip for that bill, and then various information about the waiter that received the tip as well as the the dining service that the tip was given so sunbursts makes plots that start as a py chart and again I
16:55:39 Think, this is just easier to show and then we'll talk about it.
16:55:42 So for us what we're gonna look at the pie itself is representing the total tips.
16:55:48 I think. Let's change this to tip.
16:55:53 Sorry it should have been Tip. Not total Bill. So the sunb, the the circle, is going to represent the total tip, so for us, if we go back to our data frame, you can do df.com.
16:56:06 So this circle is going to represent $731 and 58 cents, and then what it does is it's going to break it down so that $485 of that go to mail waiters.
16:56:20 And then $246 and 50 cents of that goes to female waiters.
16:56:26 So that's the first plot. And then what it does after that is, it breaks down the subgroup.
16:56:32 The main groups, which are male and female, that we're looking at.
16:56:36 It will break down each of those into the subgroups.
16:56:38 We give it, which are the days of the week. So, for instance, we can see that on Sundays male waiters in this data frame took in $186 and 78 cents.
16:56:49 So this is a way to see the distribution of subgroups of a group will also keep in mind the portion of the subgroup to the whole.
16:57:01 So like this angle here represent about a quarter of all tips.
16:57:05 Were given to males on Sundays, so it both gives the.
16:57:10 But then you can see it's a little bit more than a quarter of males, tips, so males, tips more than a quarter come from Saturday and Sunday.
16:57:19 What a quarter of all tips come from males on Sundays!
16:57:25 So some verse charts are a way to see sort of the different breakdowns of subgroups within groups while keeping the subgroups in relation to the total.
16:57:36 So how do we make this? This is one that we can make with Plotley express you call Px dot sunburst.
16:57:44 You put in its data frame, and then you put in the path argument.
16:57:48 The path argument takes in a list of how you want the circle broken down.
16:57:53 So first I wanted the tip to be broken down by sex, and then, after sex, I wanted it to be broken down by day, and then in the values argument you put in the variable that you want broken down.
16:58:05 Which for us was tip and similar. If we wanted the total bill broken down, we would put in total bill.
16:58:14 Okay.
16:58:17 But we wanted Tip
16:58:21 Okay, so those are sort of the 4 chart types that I saw in the documentation that we haven't seen before.
16:58:27 That might be worth knowing. A lot of them are used sort of in business settings.
16:58:32 There are more plot types that we haven't talked about, but we I'm sort of out of the scope of this.
16:58:38 So, for instance, there are map-based plots which I've linked to here, network plots, three-dimensional plots which we haven't touched on in any of our packages as well as you can make animations and plotley which we're not going to have time to touch on in
16:58:52 This section. So through both the chart types, we know how to make.
16:58:57 And then these new chart types that we're seeing.
16:59:00 We now have an idea, or at least links, to the documentation of how to make various chart types implies.
16:59:08 Now that we know that we're gonna sort of start to learn all the ways that you can change sort of the non graph elements like the legends, the backgrounds, the grids, the axes, etc.