Bar plots

Understanding Data Visualization

Richie Cotton

Data Evangelist at DataCamp

When should you use a bar plot?

Most common cases:

  1. You have a categorical variable.
  2. You want counts or percentages for each category.

Occasionally:

  1. You want another numeric score for each category, and need to include zero in the plot.
Understanding Data Visualization

 

When will I, will I be famous?
I can't answer, I can't answer that

Bros – "When will I be famous?"

The album cover for 'When will I be Famous' by Bros.

Understanding Data Visualization

ESPN 100 most famous athletes from 2017

Rank Last Name First Name Sport Country
1 Ronaldo Cristiano Soccer Portugal
2 James LeBron Basketball USA
3 Messi Lionel Soccer Argentina
4 Federer Roger Tennis Switzerland
5 Mickelson Phil Golf USA
... ... ... ... ...
1 https://data.world/wesmagee/2017-espn-world-fame-100
Understanding Data Visualization

Bar plot of counts by country

A bar plot of counts of people on the ESPN top 100 famous athletes list, by country. Countries are ordered alphabetically.

Understanding Data Visualization

Vertical bars

A bar plot of counts of people on the ESPN top 100 famous athletes list, by country. Countries are ordered alphabetically. The x and y axes are swapped so that the bars are vertical.

Understanding Data Visualization

Sorting by count

A bar plot of counts of people on the ESPN top 100 famous athletes list, by country. Countries are ordered by decreasing count.

Understanding Data Visualization

Children's fruit and veg consumption

n_portions year pct_children
n = 0 2001 10.921779
n < 1 2001 3.843093
1 <= n < 2 2001 23.659102
... ... ...
4 <= n < 5 2018 12.28728
5 <= n 2018 17.87497
1 https://digital.nhs.uk/data-and-information/publications/statistical/health-survey-for-england/2018/health-survey-for-england-2018-data-tables
Understanding Data Visualization

Stacking bars

A stacked bar plot of the number of portions of fruit and vegetables consumed each day by UK children versus year. Darker green colors correspond to more fruit and veg eaten.

Understanding Data Visualization

Bar plots vs. box plots

Box plots of the age of start of rule of kings and queens, one for each royal house.

A bar plot of counts of kings and queens by royal house.

Understanding Data Visualization

Other metrics than counts

Box plots of the age of start of rule of kings and queens, one for each royal house.

A bar plot of the mean age of start of rule of kings and queens by royal house.

Understanding Data Visualization

Let's practice!

Understanding Data Visualization

Preparing Video For Download...