Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Know your data
1. Look at your data
Visualize your data – categorical variables
Work with your chart 2
Check yourself 2


In the first part of this chapter, we learned that charts can help us see relationships between two numerical variables. What about categorical variables? Can we visualize relationships between them? Let's find out.

First, look at the data. This is the same data as we used before, but it's been changed into categorical form and placed in the alcohol_wealth2 dataset. As before, this dataset contains three variables:

  • country - The name of the country,
  • consumption_cat - The category of alcohol consumption; see table below for details,
  • wealth_index_cat - The country's wealth index; categories are low, lower-mid, upper-mid, and high.

Note: This data is based on observations for 169 countries. It was taken in 2010. The wealth index is taken from 2010 World Bank Group data.

Alcohol Consumption
Category Name Alcohol Consumption
(measured in litres of pure alcohol
consumed per person per year)
Low 0 to 2 liters
Medium 2 to 8 liters
High 8 and above


We know what variables we can expect in our dataset. Nevertheless, it is always valuable to see a sample of the real observations. Select the first ten observations from the alcohol_wealth2 dataset and look at them.

To do that, use the head(dataset, number) function with two arguments: the name of the dataset and the desired number of rows.

Note that both categorical variables are already saved as factors; they have a defined order, so we don't have to set this.

When you're done, press the Run and Check Code button to check your code.

Stuck? Here's a hint!

You should write:

head(alcohol_wealth2, 10)