In this recipe, we will learn how we can visualize more than one categorical variable into a single plot and see what it looks like. The command structure will be similar, but this will be applicable for factor variables.
Let's call the modified mtcars
dataset once again. After loading the modified mtcars
dataset we will select a subset of that data by taking only the factor variables:
cat_dat <- modified_mtcars[c("cyl","vs","am","gear","carb")]
Now, we will use this data to produce a plot.
The command structure is the same as with the continuous data but the input variables are factors in this case:
tableplot(cat_dat,sortCol=carb)
Though the function to produce the plot is the same for both categorical and continuous data, for the categorical data, the tableplot function produces each bar with a different color, corresponding to each category in the variable. The noticeable feature is that we have to supply the factor variable for this plot. If we do not input the factor variable, then it automatically treats the input as a continuous variable during the plotting process.
18.216.34.208