Graphics Programs Reference
In-Depth Information
Remember the graph is only part of the story. It's still up to you to inter-
pret the results. This is particularly important with relationships. You
might be tempted to assume a cause-and-effect relationship, but most of
the time that's not the case at all. Just because the price of a gallon of gas
and world population have both increased over the years doesn't mean the
price of gas should be decreased to slow population growth.
CrEATE A SCATTErPLoT
In this example, look at United States crime rates at the state level, in
2005, with rates per 100,000 population for crime types such as murder,
robbery, and aggravated assault, as reported by the Census Bureau. There
are seven crime types in total. Look at two of them to start: burglary and
murder. How do these relate? Do states with relatively high murder rates
also have high burglary rates? You can turn to R to investigate.
As always, the first thing you do is load the data into R using read.csv() .
You can download the CSV file at http://datasets.flowingdata.com/
crimeRatesByState2005.csv , but now load it directly into R via the URL.
# Load the data
crime <-
read.csv('http://datasets.flowingdata.com/crimeRatesByState2005.csv',
sep=”,”, header=TRUE)
Check out the first few lines of the data by typing the variable, crime , fol-
lowed by the rows you want to see.
crime[1:3,]
Following is what the first three rows look like.
state murder forcible_rape robbery aggravated_assault burglary
1 United States 5.6 31.7 140.7 291.1 726.7
2 Alabama 8.2 34.3 141.4 247.8 953.8
3 Alaska 4.8 81.1 80.9 465.1 622.5
larceny_theft motor_vehicle_theft population
1 2286.3 416.7 295753151
2 2650.0 288.3 4545049
3 2599.1 391.0 669488
The first column shows the state name, and the rest are rates for the dif-
ferent types of crime. For example, the average robbery rate for the United
Search WWH ::




Custom Search