Chapter 3. Data Visualization with Lattice

In the previous chapter, we discovered how to easily visualize our data using standard functions of R. You might remember that at some point, when discussing bar plots, we visualized the frequency of an attribute based on the case's membership a group. This required that we generated several plots, each displaying the data in one of the groups. Dealing with this kind of issue more easily is mostly what trellis graphics are about.

Trellis graphics allow the visualization of data based on group membership effortlessly. With features such as multipanel conditioning (Becker & Cleveland, 1996, p. 6), understanding the structure of your data becomes a seamless visualizing experience.

Multipanel conditioning means that data is displayed on multiple panels which are defined as a function of group membership. It is particularly interesting when membership to several characteristics are involved (for instance age group and gender). In these cases we are confronted with multivariate data. An interesting property of trellis graphics is that they are objects, which can be assigned a name, copied, and most importantly modified on the fly. We will discover these aspects in this chapter, as well as several types of useful plots.

Trellis graphics were introduced in the S language in the 1990s (Cleveland, 1993). The lattice package is the implementation of trellis graphics in R. It is now part of the list of packages that comes out-of-the box with R.

Loading and discovering the lattice package

The lattice package is included in R version 3. We will first load the lattice package with the command line:

library(lattice)

We can now have a look at the objects that are included in the package. This requires listing the loaded packages, which can be done by typing:

search()

The output is displayed on the image below:

Loading and discovering the lattice package

Packages in the R search path

The Lattice package is number 2 in this list. This position can vary, depending on whether you have loaded other packages as well.

The ls() function will allow us to inspect the content of lattice (or any other loaded package), as we have seen in Chapter 1, Setting GNU R for Predictive Modeling. Because the lattice package is in second position as just discussed, we type:

ls(2)

The output, composed of approximately 150 elements, is too long to be printed here. This illustrates the many graphing possibilities offered by lattice. We suggest you go through it on your screen. The idea is to get the feel of the content of the package by exploring it. If an object name seems intriguing, simply type its name, preceded by a question mark. This will launch the HTTP help server and provide you with information for that particular function. We will just comment on some elements of the package. There are some functions that produce graphic objects, such as barchart(), bwplot(), cloud(), histogram(), parallel().

There are also functions that add elements, such as points, lines, other shapes or text, to an object (during or after its creation). These include llines(), lpoints(), ltext(), and lrect(). Another type of important object of the lattice package are functions that configure panels, that is, the area that contains the visualizations, or add elements to panels on the fly. These functions start with the prefix panel. While some work with most lattice plots, others are specialized. We will only have a look at some of the features of lattice in this chapter.

We will not discuss all functions and arguments here. The interested reader can consult the package documentation available at:

http://cran.r-project.org/web/packages/lattice/index.html

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

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