Discovering multipanel conditioning with xyplot()

The first thing we will do next is to check that lattice works properly. For this example, we will use the iris dataset. The iris dataset is one of the best known in data science. It is composed of four numeric attributes Sepal.Length, Sepal.Width, Petal.Length and Petal.Width which are measures of iris plants, as well as a factor, or nominal attribute Species which describes the membership of the plants to 3 different iris species: Virginica, Setosa and Versicolor. The data set is composed of 150 observations.

Doing this first plot will also allow us to discover the formula syntax used in most plots with lattice:

xyplot(Sepal.Length ~ Sepal.Width | Species, data = iris)

In this line of code, we have used the xyplot() function to visualize the relationship between the sepal length and the sepal width of iris flowers conditioning on Species. This means that one scatterplot is produced for each of the groups. The function xyplot(), as well as most functions in the lattice package uses a formula syntax, similar to what we will use when discussing regressions. So here is a quick word about the formula syntax. The formula part of the line of code above is Sepal.Length ~ Sepal.Width. The ~ operator (tilde or wavy dash) is used to parse the left-hand side of the formula Sepal.Length here, with what we want to visualize in the y axis (or what we want to model in the case of regression for instance), from the right-hand side of the formula, where we tell R the attributes (Sepal.Width here) what we want to use on the x axis (or the predictors in a regression model).

Values on the left-hand side are usually vectors, and those on the right-hand side are usually vectors or matrices. We specify the dataset to be used after a comma, using the argument data. We will use more complex formulae later, including the case of formula with no left-hand side.

The vertical bar symbol | is a requirement of xyplot(). It means that the display is conditioned on the grouping attribute that follows (here the attribute is Species). The plot is reproduced in the figure below:

Discovering multipanel conditioning with xyplot()

Visualizing the features of the iris dataset conditioning on a group

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.142.194