Introduction to Statistics (MAT/SST 115.03 2008S)


This is an early work-in-progress.

We can make simple scatterplots using the general plot function. We use the vector of x values as the first parameter and the vector of y values as the second parameter. Generally,

plot(explanatory, response)

Here are some examples. (Of course, you'll generally get those values from an existing data set.)

plot(c(1,2,4,5,5,7,10,11), c(2,3,4,3,5,6,7,8))
plot(c(1,2,2,3,3,3,4,4,5), c(1,5,10,2,6,11,3,7,12))

You can also join the two vectors together with the ~ operation, in which case the code will look something like

plot(response ~ explanatory)

We'll tend to use whichever of these forms is most convenient at the moment.

An Alternative

The car library provides somewhat more elegant scatterplots, with the regression line and some box-and-whiskers plots added. To use that library, you need to load it first.

library(car, lib="/home/rebelsky/Stats115/Packages")

If you're working on your own computer, you need to install your own copy of that library.


Once you've loaded that library, you can make scatterplots with the scatterplot function. Typically, the first parameter is a vector of X values and the second parameter is a vector of Y values.

scatterplot(c(1,2,4,5,5,7,10,11), c(2,3,4,3,5,6,7,8))
scatterplot(c(1,2,2,3,3,3,4,4,5), c(1,5,10,2,6,11,3,7,12))

If you don't want to see the funky curve that attempts to show a best approximation, add smooth=FALSE.

If you don't want to see the regression line, add reg.line=FALSE.

Creative Commons License

Samuel A. Rebelsky,

Copyright (c) 2007-8 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. To view a copy of this license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.