Translate

Tuesday, July 23, 2013

Postscript to Data Visualization

Much to my chagrin, I realized I forgot to include one of the more interesting features in the lattice package. You can quickly turn a quantitative variable into one of levels of equal counts.  This provides a nice way of looking at slices of your data in a trellis plot.  These slices are referred to as shingles as they overlap according to your specification.

Here is a simple code example, using the quakes data included with R:

> library(lattice)
> head(quakes)
     lat          long    depth mag stations
1 -20.42 181.62   562    4.8       41
2 -20.62 181.03   650    4.2       15
3 -26.00 184.10    42     5.4       43
4 -17.97 181.66   626    4.1       19
5 -20.42 181.96   649    4.0       11
6 -19.68 184.31   195    4.0       12
#Build an xyplot of lat and long conditioned by depth
> depth = quakes$depth
> range(depth)

[1]  40 680
> Depth = equal.count(depth, number=6, overlap=.05)
> # with equal.count we now have sliced depth into 6 parts with an overlap of 5%
plot(Depth)





















xyplot(lat~long | Depth, data=quakes)

The way to read this plot is starting from the bottom left working right then the next row up from left to right.


































Enjoy.

TDM

No comments:

Post a Comment