[Return to tutorial page]

Statistics 200: Lab 8 (Friday 6 March 1998)

Today's tasks: Trellis graphics.

This week we will concentrate on a fancy graphical technique in Splus called, trellis graphics. Trellis graphics is used for constructing complicated but elegant graphics. Your task is to hand in some nice pictures. Show us your best pictures.

To get started: Generate a large matrix M (maybe 500 x 3) containing a sample from a N(0,1) distribution, for example. Multiply your matrix by some 3x3 matrix A (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 (Simple plots using trellis)

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 (Conditional plots using trellis)

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 (Returning to the old map data, but this time using trellis)

(Similar to last week's Problems 4 and 5, but this time using trellis.)
From the class 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 (Improving your trellis plots)

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 (Making your plots even more beautiful)

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.