We know what to expect from the chart. Now let's prepare the data to put on it.
The first stage of this process will generate data for the width of the rectangles. In this case, we will need percentages for each wealth category.
To do that, we will count how often each category of wealth occurs and transform that information to a percentage. Firstly, we will use the
count() function, that we already know, on our dataset to calculate frequencies. Here is how this will look:
tab <- count(dataset, variable_name)
And the new tab table will look like this:
1 cat1 30
2 cat2 23
Now we can create a new variable that corresponds to these percentages. We do this by adding the
mutate function, using these calculated frequencies:
tab <- mutate(tab, percent = n / sum(n) * 100)