Skip to Main Content
Graphing Data with R
book

Graphing Data with R

by John Jay Hilfiger
October 2015
Beginner to intermediate content levelBeginner to intermediate
250 pages
6h 26m
English
O'Reilly Media, Inc.
Content preview from Graphing Data with R

Chapter 20. Mosaic Plots

Graphing Categorical Data

Most of the graphs we have studied so far have been of quantitative variables. In a few cases, we have mixed quantitative and categorical variables, usually by making the distinct values of the categorical variable(s) define groups, each one having its own graph. Sometimes, however, all of the variables of interest are categorical. This requires special graphical methods.

Let’s consider a dataset in the epiDisplay package. You will need to install this package, as well as vcd, which includes some functions for working with categorical variables. Here’s how to do that:

> install.packages("epiDisplay")
> install.packages("vcd")
> library(epiDisplay)
> library(vcd)

We will be looking at the ANCdata dataset. You’ll need to get some information about this dataset:

> ?ANCdata

This data is from a study of the types of care given to women with high-risk pregnancies in two clinics. There are three variables, all categorical, and each has only two values, or levels. We would like to know if perinatal mortality (i.e., a stillborn fetus or death of newborn within seven days) is related to the type of treatment or the clinic in which care was received. Let’s first look at the relationship between death and anc (treatment). The table() command shown in the following script will count  the number of observations in each combination of the two variables:

 # Table 20-1 library(epiDisplay) library(vcd) attach(ANCdata) xtab1 = table(death,anc) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

A Course in Statistics with R

A Course in Statistics with R

Prabhanjan N. Tattar, Suresh Ramaiah, B. G. Manjunath

Publisher Resources

ISBN: 9781491922606Errata Page