Introduction to Statistics (MAT/SST 115.03 2008S)

R notes for Activity 2-3

Activity 2-3 b asks you to make a dotplot from some data. You can enter the data by hand. (We've just entered the first few numbers.)

> StatesVisited = c(20, 37, 15, 19, 21, 15, 4)

You can also read the data from a CSV file we've created. In this case, we'll need to extract the one column from the data before we plot it.

> StatesTable = read.table("/home/rebelsky/Stats115/Data/states.csv", header=TRUE)
> StatesVisited = StatesTable[,1]

Now, we're ready to “create a visual display”. The book asks us to create a dotplot, but that's partially because dotplots are easier when you're doing things by hand. Since the computer is doing it, we might try a histogram with 50 columns (one per data value).

> hist(StatesVisited, breaks=50, plot=TRUE, main="States Visited by Statistics Students")

Of course, you'll need to play with the axes a little bit, but this is a good start.

You might also try R's dotchart function, but that doesn't seem to work very well with this kind of data. Also, remember that the basic dotchart needs to have you tabulate the data first.

> dotchart(table(StatesVisited), main="States Visited by Statistics Students")

Nope, not a very useful plot. So, we'll use the dotPlot extensino, which comes with the BHH2 package.

> install.packages("BHH2")
> library(BHH2)
> dotPlot(StatesVisited, main="States Visited by Statistics Students")

Much better! Of course, we should still create better labels on the X axis.

> dotPlot(StatesVisited, main="States Visited by Statistics Students", axes=FALSE)
> axis(1, seq(from=0,to=50,by=5))

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.