O'Reilly logo

R Statistical Application Development by Example Beginner's Guide by Prabhanjan Narayanachar Tattar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – the mosaic plot for the Titanic dataset

The goal here is to understand the survival percentages of the Titanic ship with respect to Class of the crew, Sex, and Age. We use first xtabs and prop.table to gain the insight for each of these variables, and then visualize the overall picture using mosaicplot.

  1. Get the frequencies of Class for the Titanic dataset with xtabs(Freq~Class,data=Titanic).
  2. Obtain the Survived proportions across Class with prop.table( xtabs(Freq~Class+Survived,data=Titanic),margin=1).
  3. Repeat the preceding two steps for Sex: xtabs(Freq~Sex,data=Titanic) and prop.table(xtabs(Freq~Sex+Survived,data=Titanic),margin=1).
  4. Repeat this exercise for Age: xtabs(Freq~Age,data=Titanic) and prop.table(xtabs(Freq~Age+Survived,data=Titanic), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required