A bar chart needs some numerical values for each group. In our problem, we will use the frequency of each category as the numerical values.
To find out these frequency values, we have to create a frequency table for the categorical variable (in this case, the
pattern variable). Our frequency table looks like this:
The first column (
pattern) presents every possible or considered value of the
pattern variable. The second column (
n) shows how many times a value occurs in the dataset – in our case, this is the number of countries classified by each category.
We will need this frequency table to create a bar chart, so now you'll build one for yourself. To do that in the R programming language, you need to use the count function, which looks like this:
It takes two arguments: the dataset name and the name of the variable we are using for our frequency table categorical data.