[Return to syllabus page]

Statistics 200: Lab 8

Today's tasks: Trellis graphics.

This week we will concentrate on a fancy technique, trellis graphics, for constructing complicated but elegant graphics. Your task is to hand in some beautiful pictures. Show us your best picture.

To get started: Generate a large matrix (maybe 500 x 3) containing a sample using rnorm. Multiply by some 3x3 matrix (something not too simple--maybe 9 random numbers) to get a matrix of observations on a multivariate normal. Call the columns of the matrix xx, yy, and zz.

Start trellis:

trellis.device(win.graph)    #starts up the trellis device for windows
Get help on xyplot().

At some stage during the lab you should assign the output from xyplot to an object, then look at the attributes of that object.

Problem 1

First just use xyplot() to plot yy versus xx. Then try for something a little fancier, by writing a panel function that plots the points and draws the least-squares line. Hint: look at panel.xyplot() for some ideas.

Problem 2

Use the equal.count() function to create a shingle called zslices, dividing the zz range into four slightly overlapping subranges. Repeat the exercise from Problem 1, using xyplot with the yy,xx, and zslices arguments to create a display with four little plots (don't use mfrow()--trellis takes care of the multiple plots), each showing a scatterplot with least-squares line for yy versus xx in the different ranges defined by zslices.

Problem 3

(Similar to last week's Problems 4 and 5, but this time using trellis.)
From the library (mapsdata section, the oldmap.df), get the oldmaps data from last week, but in the form of a single dataframe with the names of the source maps as a factor.

Write a function that accepts vectors of oldmap coordinates, (representing the 39 points from a map, with suspect observations flagged by minus signs) as arguments. Your function should plot the points for the old map, together with arrows (or line segments) joining the points to the corresponding Actual locations. Be sure that you have west pointing to the left. If you are ambitious, try to superimpose a map of the US (using the usa() function), so that you can see where the actual landmarks are. It would also be nice if you could somehow indicate those points that are flagged (by the minus signs) in the data set as suspect--maybe use different plotting symbols to indicate suspect points.

Problem 4

Modify your function from Problem 3 so that it can be used as the panel argument for xyplot. Generate a trellis display, one little picture for each old map, with each picture looking like the map drawn in Problem 3.

If you wish to be very fancy, try to achieve some of the following effects:

Problem 5

Write a function to produce the following trellis display: For each old map, fit a linear model (~ Actual$lat + Actual$long) to the latitude and longitude. For each panel, show the residuals for the old map by little arrows that are anchored at the Actual locations of the landmarks. Embellish appropriately.