Graphics Programs Reference
In-Depth Information
The first line stores all rows that aren't for the District of Columbia in
crime2 . Similarly, the second line filters out the United States averages.
Now when you plot murder against burglary, you get a clearer picture, as
shown in Figure 6-4.
plot(crime2$murder, crime2$burglary)
FIGurE 6-4 Scatterplot after filtering data
Although, it could probably be better if the axes started at zero, so do that,
too. The x-axis should go from 0 to 10, and the y-axis will go from 0 to
1,200. This shifts the dots up and to the right, as shown in Figure 6-5.
plot(crime2$murder, crime2$burglary, xlim=c(0,10), ylim=c(0, 1200))
You know what would make this plot even more useful? A LOeSS curve like
you saw in Chapter 4. This would help you see the relationship between
burglary and murder rates. Use scatter.smooth() to make the line with the
dots. The result is shown in Figure 6-6.
scatter.smooth(crime2$murder, crime2$burglary,
xlim=c(0,10), ylim=c(0, 1200))
Search WWH ::




Custom Search