(plot-points x-variable y-variable)Our y-variable will be "2D precipitation, the variable we defined earlier. As our x-variable we would like to use a sequence of integers from 1 to 30. We could type these in ourselves, but there is an easier way. The function "2D iseq, short for integer-sequence, generates a list of consecutive integers between two specified values. The general form for a call to this function is
(iseq start end).To generate the sequence we need we use
(iseq 1 30)Thus to generate the scatter plot we type
> (plot-points (iseq 1 30) precipitation) #<Object: 3423466, prototype = SCATTERPLOT-PROTO> >and the result will look like Figure
Sometimes it is easier to see temporal patterns in a plot if the points are connected by lines. Try the above command with "2D plot-points replaced by "2D plot-lines.
The "2D plot-lines function can also be used to construct graphs of functions. Suppose you would like a plot of sin(x) from - π to + π. The constant π is predefined as the variable "2D pi. You can construct a list of n equally spaced real numbers between a and b using the expression
(rseq a b n).Thus to draw the plot of sin(x) using 50 equally spaced points type
> (plot-lines (rseq (- pi) pi 50) (sin (rseq (- pi) pi 50))) #<Object: 3423466, prototype = SCATTERPLOT-PROTO> >The plot should look like Figure
Scatterplots are of course particularly useful for examining the relationship between two numerical observations taken on the same subject. Devore and Peck [8, Exercise 2.33] give data for HC and CO emission recorded for 46 automobiles. The results can be placed in two variables, "2D hc and "2D co, and these variable can then be plotted against one another with the "2D plot-points function:
> (def hc (list .5 .46 .41 .44 .72 .83 .38 .60 .83 .34 .37 .87 .65 .48 .51 .47 .56 .51 .57 .36 .52 .58 .47 .65 .41 .39 .55 .64 .38 .50 .73 .57 .41 1.02 1.10 .43 .41 .41 .52 .70 .52 .51 .49 .61 .46 .55)) HC > (def co (list 5.01 8.60 4.95 7.51 14.59 11.53 5.21 9.62 15.13 3.95 4.12 19.00 11.20 3.45 4.10 4.74 5.36 5.69 6.02 2.03 6.78 6.02 5.22 14.67 4.42 7.24 12.30 7.98 4.10 12.10 14.97 5.04 3.38 23.53 22.92 3.81 1.85 2.26 4.29 14.93 6.35 5.79 4.62 8.43 3.99 7.47)) CO > (plot-points hc co) #<Object: 3423466, prototype = SCATTERPLOT-PROTO> >The resulting plot is shown in Figure