Welcome back. This video,
I'm going to walk you through some of the different types of charts that we're going to be learning how to create outcomes or
be able to identify the appropriate type of chart for data in a question and understand key rules to avoid common errors.
I'm not going to be showing the detailed code for these chart types in the video.
You're going to be able to find that in the documentation link from here. And also,
I'm going to be preparing a notebook that demonstrates various of these charting
types with the actual code to create them using the software we discussing.
So common software for this or Seabourne and matplotlib, those are going to be the primary ones that we're working with this semester.
When I'm showing the function names, Seabourne is commonly input imported S.A.S.
So as an ascot function is going to be a seabourne function PLDT,
the function is going to be a matplotlib of function and also showing the function you can use in plot nine or Ares g.G plot too,
if you want to use those instead. I often use plot nine for a lot of my graphics.
That's just for reference though. We're not going to be getting into much detail on Plot nine in the course of this course.
So there's a variety of different types of charts. Some of them are showing relative proportions.
Some of them are showing how different amounts relate to each other. Some of them are showing positions and an x y coordinate space.
A bar chart is a very common type of chart that shows numeric values grouped by a categorical or ordinal variable.
Sometimes they're grouped by New America as well.
But usually our x axis is a categorical variable of some kind best with a moderate number of categories.
We can use a second categorical variable to say color the bars.
So this chart shows the survival rates of Titanic passengers or the X axis is the passage class for second or third class.
And then the bars are colored based on the gender of the of the passenger.
And so we can see the different survival rates.
The y axis on a bar chart is often a mean or a sum or a count within the cap of the group determined by our categorical variables.
Sometimes these will be horizontal. So the horizontal bar chart, the categorical is on the Y and the bars run horizontally.
This also shows some whiskers that come from a confidence interval.
It's very easy to generate a default, relatively good confidence interval with Seabourne so tough to pluck to plot
these Seabourne has the count plot function which lets which does a quick,
basically categorical histogram. How many observations are in each are in each category.
The cap plot variable will plot by default a mean value for each category.
And if you have it, do the mean plotting. It will also compute. Ninety five percent confidence intervals.
That's what's being shown in this in this plot here.
And then you can also use the bat, the bar function or the plot nine Geon Bar.
So if you rules about bar charts first is never start the Y axis on a bar chart.
Anything but zero. And so the reason for this we can see here is that.
So the top one. So these are these are looking at the mean average ratings.
We take you to movies, mean rating, and then we compute the mean of the average ratings within a genre.
What is that? So if we look here, the difference between horror and IMAX, it's a notable difference, but it's a difference of about point five or so.
The difference between sci fi and short is a difference of a little under one, probably.
But when we start the Y axis at 2.5 instead of zero,
what happens is the differences look much larger than they are because the human eye, naturally it's not.
We not only want to see the difference, but we want to it's very natural for us to compare the difference to the bar length because these are bars.
They have length, they have an area since they're all the same with the length is proportional to the area.
Braking length area. Proportionality is a good way to confuse your readers,
but it looks like IMAX movies have twice as high an average rating as horror movies because the bar is twice as high, but they don't.
It's really a shift from about 2.8 to three point three or three point four.
And so it creates a distortion that makes the different like it highlights the differences, but it makes the differences look larger than they are.
So when I talked about integrity and avoiding deception, when I was introducing statistical graphics,
this is what I was talking about, the differences there. It's just not as big as it looks like it is.
And we truncate our bar charts.
So if you have the general rule here to generalize beyond bar charts is if something has a length that varies based on the data,
that length needs to actually represent the value, not the value, minus something because you started the axis somewhere else.
So if you're including Whiskers, like I did in the previous chart,
define how they're computed and also as one thing to just be careful of seaboard's cat platen count plot.
If you aren't using the color for a second variable, they will just make every bar a different color for no particular reason,
which it creates something that's different when it doesn't need to be so.
It causes the reader to look for a difference that isn't actually their best avoided.
You can fix that by just specifying the color.
We saw histograms last week in a histogram as a bar chart, but a categorical was Binz or ranges of a numerical value.
Also, though, if we have a bar chart that's showing the relative frequency of categorical variables that can also be called a histogram,
the Y axis is either the number or the fraction of occurrences in this case.
So we can that. The key thing, though, is the different heights of the bars that I see visually, the relative frequency of different values.
So it really makes it visually clear how the data is shaped.
We can see Skewes and things like that. Is there one way to graphically describe a distribution?
A scatterplot shows two numeric variables. So each observation is a dot.
Each observation has two numeric variables. And we put the one variable on the x axis.
The other variable on the Y axis and put the dot at where its variable values would intersect.
This is really useful for seeing how two variables relate. Does one increase with the other Duplin?
Do points clump or cluster in an interesting way? Other interesting patterns.
It helps us find outliers. So this this is scatterplot is showing the tip versus the total bill for a bunch of restaurant bills.
And each each observation is a bill.
And then the x axis is the the under the total bill on the Y axis is the tip that the that the the customer added to the bill.
And we a couple of refinements we can do here. We can color or change to the point tight by a categorical variable.
So on this one, we've changed it so that the points are different color.
So those dinners are blue circles and the lunches are orange AXA's.
We could also add a trend line or some other kind of a line to show some context, for example, on this chart,
we might want to plot a line that shows that the 20 percent point and that let us easily see where we're going over 20 percent,
how that the tips are distributed relative to it to a 20 percent mark.
We can also X can be a categorical variable when that happens. We call this a point plot or a strip plot.
Functions for doing this are scatter scatterplot and then plotlines John Point,
the Seabourne documentation has some examples of more of these align plot.
It's like a scatterplot that we have to numeric variables. However, we it emphasizes the progression or continuity from one variable to the next.
By combining them with a line, it really works best. We have one Y per X value that we want to plot.
If we've got more than one, it really starts getting very, very jagged. It's very common for Time series.
So this is another example from the Seabourne tutorial not labeled super well.
I don't know what the value actually is, but it shows that we have some kind of a value that's changing over time and it's going negative.
That was zero. The Y axis is at the top and the values otherwise our negative functions to create.
These are line plot from seabourne, line from a matplotlib and Gyeom line from plot nine.
A box plot shows the distribution of a numeric variable grouped by a categorical.
So the bar chart just showed us, say, the average value, maybe with confidence interval.
The box plot actually shows us the distribution and it does so in a way that's based on the median.
So the median, the the horizontal line in the middle of the box is the median value, the top and bottom of the box.
Are the first and third quarter close to the bottom of the first quartile and the top as the third quartile.
And what that means is twenty five percent of the values are below the bottom of the box.
Twenty five percent in the bottom half. Twenty five percent here and then twenty five percent above.
We then show these these whiskers that extend out to the minimum,
a maximum of the data and a number of plotting packages will do some kind of an outlier detection.
This is using seabourne default outlier detection. So if the max is very high and what the rule it uses by default is it allows the whisker to be.
So you've got the IQ are the inter quartile range. That's the height of the box. It allows the whisker to be one point five times that tall.
And if you have any data points that are further away than that, it plots them as individual points, makes it easy to see outliers.
You can change. It's that the whisker goes all the way up to the max, but it lets you quickly see and compare between different groups.
The median, the first and third quartiles and the men in the max to the data.
Very useful for comparing observations of a variable when you're grouped by some categorical functions
for doing this or box plot from both Seabourne and matplotlib and then Gyeom block box from plot nine.
A few more plots, a violin plot. It's like a box plot, except it's based around the mean and has curved sides.
The swarm plot is a kind of another kind of a categorical scatterplot.
It's usually best to avoid pie charts, especially 3D pie charts, or a lot of the of our software is not going to produce 3D charts very easily.
Don't try to go make a 3D chart. They're almost always more confusing, especially like the 3D bars that you have from vintage PowerPoint.
But even a pie chart, just because the human perception is not super great at accurately comparing angular areas.
So usually a bar chart,
restacked bar chart is going to be a better option than a pie chart or a donut chart is sometimes a better option where you've got to circle.
This is one place where I disagree with the reading. The reading that I gave you recommends pie charts for showing relative proportions.
I recommend usually avoiding those use a bar chart is a stacked bar chart if you need to show you
want to show multiple proportions of different or relative proportions within different categories.
There's another kind of plot that's not a plot on its own, but it's combined with other kinds of plots.
That's a rug plot useful for just displaying distributions at a margin.
So to learn more, I've gone I've taken a whirlwind tour through a number of different plot types, the class readings.
So the paper that I assigned you to read, it talks through the use cases for a number of different plot types.
I'm going to be providing tutorial notebooks that walk you through different plot types.
The textbook talks about graph plotting and data visualization.
The Seabourne and matplotlib docs are extensive. And for what?
If you're using another plodding library, its documentation as well. Most plotting libraries also have a gallery student.
Go through the gallery, look for a plot that has a feature you want in your plot or that you think might be useful for displaying your data.
Click on it and they'll give you the code to show you how they made that plot.
You might want to combine pieces from multiple plots. In practice, it takes a lot of trial and error to really get the hang of your plot and library
and figure out how to make it show you the data in the way you really want it to.
Learning one plotting library really deep is useful for a lot of the a lot of the python ones,
especially the ones that are oriented towards static charts. They're built on top of matplotlib.
So Seabourne is a convenience API on top of matplotlib. If you're using Seabourne,
you're also going to need to use matplotlib calls a lot of the time when the seabourne gets you 90 percent of the way there,
but not quite all the way. So to wrap up, there are many different types of charts that have different use cases.
Learning graphics techniques takes time and practice takes some of the example notebooks that I'm providing.
Take some of the galleries from the examples from, say, the Seabourne Gallery.
Play with them, play with them with some data that I'm giving you, play with them with some data that you have elsewhere.
But it takes time and practice and spend some time with the galleries of the of the the plotting libraries you're using.