Book Image

R Graphs Cookbook Second Edition

Book Image

R Graphs Cookbook Second Edition

Overview of this book

Table of Contents (22 chapters)
R Graphs Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Multivariate categorical data visualization


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.

Getting ready

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.

How to do it…

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)

How it works…

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...