We talked in the last lecture about histograms.
Now we want to talk about a very similar type of plot, which is the bar plot and an example of a bar
plot or bar chart looks like this.
Remember that we use histograms for continuous variables like age or time or temperature.
So we have that continuous variable along the horizontal axis.
When we use a bar plot, it's usually for a categorical variable which we put along the horizontal axis.
So here, for example, is a bar plot of the number of times that each continent has hosted the Summer
Olympic Games.
So we have Europe, North America, Asia, Australia and South America and this variable which we could
call continent.
So if we say that along the horizontal axis here, we plot continent, continent is a categorical,
not continuous variable.
Obviously there's nothing continuous about different continents.
There's no continent in between Europe or North America or a continent in between North America and
Asia.
In the same way that if we plot age along the horizontal axis, we can think about in between values,
because age can take on every value as long as we can measure age to a detailed enough degree.
But there's no in between concept here with continents.
These are just different buckets, different categories.
So this is a categorical, not continuous variable.
When we have a variable like this, it's really common to use a bar plot or bar chart because it's one
of the simplest ways to summarize and graphically represent.
A set of data will usually just put the categorical variable along the horizontal axis and then we'll
put count along the vertical axis.
So we could say here that this is count.
And again, this particular bar chart is the number of times each continent has hosted the Summer Olympic
Games.
When we're talking about a categorical variable, we usually refer to each category as an individual.
So we plot the individuals of the categorical variable along the horizontal axis.
Keep in mind, though, that for bar charts or bar graphs, not only can we create a chart where the
bars are shown vertically, we can also create this same chart where the bars are shown horizontally.
This is exactly the same chart, except that we have flipped the axes.
We have the continents here, the categorical variable along this vertical axis, and then along the
horizontal axis we have the count.
Notice one thing that these charts have in common.
We don't always have to do this, but it can be nice for a bar graph to organize the data from least
to greatest or greatest, to least notice that we have arranged the individuals in this categorical
variable.
We have arranged the continents in such a way that we're showing the continent that's hosted the Summer
Olympics the most times first, and then all the way down to the least number of times last.
And then same thing here with the bar chart flipped the other way.
We have the continent with the highest count on top, all the way down to the lowest count on the bottom.
It can be nice to arrange the data that way because visually it makes it really easy for us to see highest
count, lowest count and everything in between.
But depending on the variable, sometimes it's not going to make sense to put the data in order by count.
For instance, maybe our categorical variable is months of the year, so January, February, March,
April, etc. all the way to December.
If that's the case, we could certainly rearrange the months based on count and show the greatest count
first and the lowest count last.
But it also might make the most sense just to show the months in order, starting with January ending
in December.
It always comes back to what we're trying to represent and what makes most sense to communicate the
picture we're trying to get across.
Notice also that with these bar graphs, we always show a space or a gap between each bar, whereas
with the histogram we eliminated that space between the bars.
And so we had what looked like one continuous distribution that was intentional to indicate that we
were dealing with a continuous variable.
These gaps or breaks or this separation in between each bar indicates or gives us another hint that
we're dealing with a categorical variable.
Realize here that any bar plot or bar chart is associated with a frequency table.
So the raw data for these charts might be the complete historical list of the host city for every summer
Olympic Games.
And using that raw data, we could make a frequency table so we could take every instance of the Summer
Olympic Games and create a table where we group those games together by continent.
And so our table might look like this.
Europe, North America.
Asia, Australia and South America.
And then our count.
Of games would be 16, six, three, two and one.
So this is continent.
And this is count and this is what we call the frequency table that we can use to build a bar chart
or bar plot or bar graph.
Obviously, once we have this frequency table, we would list the individuals in the categorical variable
across the horizontal axis, or if we're doing our chart horizontally across the vertical axis.
And then we would just make sure that each bar extends to the correct count of that individual.
So.
Europe has hosted the Summer Olympic Games 16 times.
So when we create a category here for Europe, we show a bar that extends up to this point here, 16
and then we show North America right about here at six, etc..
And so we plot those bars.
And then the last thing we want to say about bar plots is that they are also great for comparing two
different variables.
For instance, maybe we want to compare summer and Winter Olympic Games in this chart we're showing.
Summer games in blue and we're showing.
Winter Games in green.
If this is the case, we obviously want to make sure to include a legend like this that we've shown
here.
Maybe we would do something like this, but we want to indicate which series is associated with which
set of games.
And these bar charts are a really good way to show the comparison between these, because not only can
we see the comparison between games for each continent, so we can quickly see here that Europe has
hosted the Summer Olympics more than the Winter Olympics, whereas it looks like North America has hosted
an equal number of summer and Winter Olympic Games.
But we can also quickly compare the Summer Olympic Games by continent and the Winter Olympic Games by
continent.
So there's several things we can do all in one chart and we can do it very quickly.
So simple idea here with bar graphs.
The biggest takeaway being that we use a bar graph when we're dealing with a categorical variable,
whereas we use a histogram when we're dealing with a continuous variable.
And if we're creating a bar graph, we want to make sure to leave space in between the bars.
Whereas when we create the histogram, we want to make sure to show no space at all between the bars
so that we can make it clear whether we're dealing with a histogram or a bar graph.
And then assuming we are dealing with a bar graph, if we're starting from a frequency table like this
one, we just want to decide whether or not it makes more sense to order our data by count like we did
here from largest to smallest count, or whether it makes sense to show the individuals in the categorical
variable in a different order like we talked about earlier.
If our individuals are months of the year and maybe it makes more sense to show them chronologically
is January, February, March, etc., even if the counts then aren't in order from largest to smallest.