# More Multivariate Data Visualization

Summary: We explore further techniques for visualizing a simple multivariate data set.

Contents:

## Preparation

a. We'll be working in both DrScheme and GIMP, so open a new DrScheme window and a new GIMP window. In the GIMP, open a ScriptFu console. In that console, load our course GIMP library.

```(load "/home/rebelsky/Web/Courses/CS151/2006F/Examples/gimp.scm")
```

b. If you have not done so already, make the file `us1.txt` as described in the previous lab.

## Exercises

### Exercise 1: Preprocessing the Data, Revisited

a. Make a copy of `datavis.scm`.

b. Scan through that file to make sure that you understand the purpose of the various procedures. (The `preprocess` procedure is the most important one.)

c. As most of you noted on the first day exploring data visualization, it's a pain to manually preprocess the data from the file. Hence, the `preprocess` procedure should do it for you.

d. Define a list of data points with

```(define data-points (preprocess "/home/username/Desktop/us1.txt"))
```

### Exercise 2: Continuing the Previous Lab

b. Make sure that the `plot` procedures you wrote in the previous laboratory (and any other related procedures) are in your library for this laboratory (`datavis.scm`).

### Exercise 3: Scaling and Shifting, Automated

a. Expand each vector in `data-points` by adding a GNP-per-capita value.

b. Write a procedure, `(vmax vecs pos)`, that, given a list of vectors, `vecs`, and a position, `pos`, finds the largest value at position `pos` in each vector. For example,

```> (define vectors (list (vector 1 2 4 8) (vector 2 2 2 2) (vector 0 5 0 5)))
> (vmax vectors 0)
2
> (vmax vectors 1)
5
> (vmax vectors 2)
4
> (vmax vectors 3)
8
```

c. Write a similar procedure, `(vmin vecs pos)`, that computes a corresponding minimum value.

d. Write a procedure, `(vshift! vecs pos amt)`, that adds `amt` to the value at position `pos` in each vector in `vecs` and returns the modified list.

e. Write a procedure, `(vscale! vecs pos amt)`, that multiplies by `amt` the value at position `pos` in each vector in `vecs` and returns the modified list.

```(define normalize
(lambda (vecs pos)
(let* ((maxval (vmax vecs pos))
(minval (vmin vecs pos))
(scale (- maxval minval)))
(vscale! (vshift! vecs pos (- minval)) pos (/ 1 scale)))))
```

g. Normalize the values in `data-points`. For example, you might write,

```(normalize data-points 0)
(normalize data-points 1)
(normalize data-points 2)
(normalize data-points 3)
```

h. Rewrite `plot` to accept normalized values.

i. Graph the values in the vector with

```(map (lambda (point) (plot img point)) data-points)
```

### Exercise 4: Alternate Visualizations

Now that all of the values are normalized, you can use any of the values as the x value, any of the values as the y value, and any of the values as the color value or radius. Write a variant of `plot` that makes different choices about the index of each.

## History

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Thu Nov 30 21:43:04 2006.
The source to the document was last modified on Wed Nov 29 09:23:17 2006.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2006F/Labs/more-multivariate-visualization.html`.

You may wish to validate this document's HTML ; ;

Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright © 2006 Samuel A. Rebelsky. This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. To view a copy of this license, visit `http://creativecommons.org/licenses/by-nc/2.5/` or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.