O'Reilly logo

R: Data Analysis and Visualization by Ágnes Vidovics-Dancs, Kata Váradi, Tamás Vadász, Ágnes Tuza, Balázs Árpád Szucs, Julia Molnár, Péter Medvegyev, Balázs Márkus, István Margitai, Péter Juhász, Dániel Havran, Gergely Gabler, Barbara Dömötör, Gergely Daróczi, Ádám Banai, Milán Badics, Ferenc Illés, Edina Berlinger, Bater Makhabel, Hrishi V. Mittal, Jaynal Abedin, Brett Lantz, Tony Fischetti

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

Creating a conditional histogram

A histogram is one of the simplest ways to visualize the univariate distribution. Sometimes, we need to produce a histogram for each group in order to compare the distribution in a subgroup of another categorical variable. In this recipe, we will see how we can create a conditional histogram using the lattice functionality.

Getting ready

To visualize a conditional histogram, we need at least one numeric variable and one categorical variable. We have all this information in the dataset that we have simulated in earlier recipes. Here, we will reproduce the same cross-tabulation raw data with the following code:

# Set a seed value to make the data reproducible set.seed(12345) cross_tabulation_data <-data.frame(disA=rnorm(n=100,mean=20,sd=3), ...

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