88  Case Study 1 — Iris

Understanding the data layer is crucial to building plots efficiently using the grammar of graphics framework. Consider the following example using the classic Iris data set.

The data set contains observations for 150 flowers each from three species of Iris, Iris setosa, Iris versicolor and Iris virginica. Four variables were measured on each flower: The petal length and width and the sepal length and width. The sepals are typically the green outer layer of flowers, but in this case they are a colorful part of the flower.

Figure 88.1: The three Iris species in the iris dataset. Iris setosa, Iris versicolor and Iris virginica

In the form presented in table XX, the measurements of the three Iris species can be plotted on a single plotting space. This is practical for making comparisons among a small number of sub-sets.

Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.099182 3.505011 1.411859 0.1909784 setosa
4.906041 2.996428 1.382701 0.2169218 setosa
4.682389 3.185782 1.281282 0.2083006 setosa
Figure 88.2: An example of plotting with five variables.

Figure 88.3: An example of plotting with five variables.

Figure 88.4: An example of plotting with five variables.
Species key value
setosa Sepal Length 5.1
setosa Sepal Length 4.9
setosa Sepal Length 4.7
Figure 88.5: An example of plotting with three variables.

Figure 88.6: An example of plotting with three variables.
Species Part Length Width
Setosa Petal 1.411859 0.1909784
Setosa Petal 1.382701 0.2169218
Setosa Petal 1.281282 0.2083006
Figure 88.7: Plotting four variables.

Figure 88.8: Plotting four variables.
Species Part Length Width
setosa Petal 1.4 0.2
setosa Petal 1.4 0.2
setosa Petal 1.3 0.2
Figure 88.9: Further example of plotting with four variables.

Figure 88.10: Further example of plotting with four variables.
Species Part Length Width PartSpec
setosa Petal 1.411859 0.1909784 setosa.Petal
setosa Petal 1.382701 0.2169218 setosa.Petal
setosa Petal 1.281282 0.2083006 setosa.Petal
Figure 88.11: Combining variables.

Figure 88.12: Combining variables.

Further examples
Species Measure Petal Sepal
setosa Length 1.411859 5.099182
setosa Length 1.382701 4.906041
setosa Length 1.281282 4.682389

Further examples

Species Measure Petal Sepal MeasSpec
setosa Length 1.411859 5.099182 setosa.Length
setosa Length 1.382701 4.906041 setosa.Length
setosa Length 1.281282 4.682389 setosa.Length
Figure 88.13: Further examples

Figure 88.14: Further examples