Ok. We now know what data we need and what we should achieve after the first step of our mosaic plot construction project. In reality, when you use ggplot2 you don't have to prepare data for a mosaic plot – a new geometry called
geom_mosaic will take care of it. Nevertheless, knowing what values are encoded in the mosaic plot is crucial if you want to understand this complicated chart.
To create this first stage of the mosaic plot using R, you have to add
geom_mosaic to the main
ggplot(data = dataset) + geom_mosaic(aes(x = product(variable_x)))
Note that you specify which variable will be on the horizontal axis by the argument
product(variable_x). Obviously, the variable name will replace the
variable_x placeholder text.