Graphics Programs Reference
In-Depth Information
To create the step chart in R, follow the same process you've been using
throughout the chapter:
1. Load the data.
2. Make sure the data is properly formatted.
3. Use an R function to produce a plot.
You can find historical postage rates, along with many other datasets, from
the United States Statistical Abstract. I've put it in a CSV file found at http://
datasets.flowingdata.com/us-postage.csv . Plug that URL into read.csv() as the
source to load the data file into R.
postage <- read.csv(“http://datasets.flowingdata.com/us-postage.csv”,
sep=”,”, header=TRUE)
Following is the full dataset. It's only ten points, one for each postage rate
change from 1991 to 2009, and a last point to indicate the current rate. The
first column is year and the second column is rate in U.S. dollars.
Year Price
1 1991 0.29
2 1995 0.32
3 1999 0.33
4 2001 0.34
5 2002 0.37
6 2006 0.39
7 2007 0.41
8 2008 0.42
9 2009 0.44
10 2010 0.44
The plot() function makes it easy to create a step chart. As you would
expect, you plug in the year as the X-coordinate, price as the Y-coordinate,
and use “s” as the type , which of course stands for step.
plot(postage$Year, postage$Price, type=”s”)
You can also specify main title and axis labels, if you like.
plot(postage$Year, postage$Price, type=”s”,
main=”US Postage Rates for Letters, First Ounce, 1991-2010”,
xlab=”Year”, ylab=”Postage Rate (Dollars)”)
Search WWH ::




Custom Search