When we want to visualize more than one summarized numeric variable over the category of another variable, we need to produce a stacked bar chart. In this case, each bar represents summary statistics of each variable. The different variables occupy different heights with various colors in that single bar.
To produce stacked bar charts, we will use the same summarized data that we created in the Creating bar charts recipe.
The command that produces the stacked bar chart is exactly the same as the simple bar chart. The only difference is that we need a new argument, which is stack=TRUE
:
barchart(disA+disB+disC~factor(age),data=dis_dat,stack=TRUE)