Get startedGet started for free

Even prettier: the Mosaic Plot

The table command can be used to tabulate any number of variables that you provide. This means you can investigate how different categories relate to each other. For example, you can see how many people have smoked at least 100 cigarettes in the different general health groups by executing

table(cdc$genhlth, cdc$smoke100).

Go ahead and try this in the console before starting of with the challenges.

To have a nice graphical representation of this distribution you can use the mosaicplot() command.

This exercise is part of the course

Data Analysis and Statistical Inference

View Course

Exercise instructions

  • Use the table() function to see how many participants have smoked across each gender. Assign this table to gender_smokers.
  • Plot the contents of this table using the mosaicplot() function.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# The cdc data frame is already loaded into the workspace

# How many participants have smoked across gender?
gender_smokers <-

# Print out gender_smokers
gender_smokers

# Plot the mosaicplot
Edit and Run Code