Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Playing with Earthquake Data
========================================================
This is a little example inspired by Jeff Leek's [Data analysis class](https://class.coursera.org/dataanalysis-001/). Jeff pointed us towards some data from the [US Geological Survey](http://www.usgs.gov/) on earthquakes. I believe these are the earthquakes for the last 7 days. I decided to see what I could do with it.
```{r}
fileUrl <- "http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M1.txt"
download.file(fileUrl,destfile="./data/earthquake_7day.csv",method="curl")
eq <- read.csv("./data/earthquake_7day.csv")
```
Let's be good citizens and record the provenance of our data.
```{r}
attributes(eq)['date.downloaded'] <- date()
attributes(eq)['url'] <- fileUrl
save(eq, file='earthquakes_7day.RData')
```
```{r echo=FALSE}
attributes(eq)['date.downloaded']
```
Let's see what they give us.
```{r}
colnames(eq)
```
Something looks a little funny about the distribution of magnitudes. What's up with that bump at magnitude 5? My guess is that there some detectors are more sensitive than others and the less sensitive ones bottom out at around 5.
```{r fig.width=6, fig.height=4}
hist(eq$Magnitude, main="Histogram of Earthquake Magnitude", col="#33669988", border="#000066")
```
I'm guessing that the better detectors are on the west coast of the US.
```{r fig.width=6, fig.height=4}
westcoast <- c(
'Northern California',
'Central California',
'Southern California',
'Greater Los Angeles area, California',
'Santa Monica Bay, California',
'Long Valley area, California',
'San Francisco Bay area, California',
'Lassen Peak area, California',
'offshore Northern California',
'Washington',
'Seattle-Tacoma urban area, Washington',
'Puget Sound region, Washington',
'Olympic Peninsula, Washington',
'Mount St. Helens area, Washington',
'San Pablo Bay, California',
'Portland urban area, Oregon',
'off the coast of Oregon')
hist(eq[eq$Region %in% westcoast,'Magnitude'], main="Histogram of Earthquake Magnitude - West Coast US", col="#33669988", border="#000066")
```
Now that looks a little smoother. Let's try R's mapping ability. Check out the ring of fire.
```{r fig.width=7, fig.height=4}
library(maps)
map()
points(x=eq$Lon,y=eq$Lat,col=rgb(1.0, 0.0, 0.0, alpha=0.3), cex=eq$Magnitude*0.5, pch=19)
```
Zoom in on the west coast.
```{r}
map("state", xlim = range(c(-130,-110)), ylim = range(c(25,50)))
points(x=eq$Lon,y=eq$Lat,col=rgb(1.0, 0.0, 0.0, alpha=0.3), cex=eq$Magnitude*0.5, pch=19)
```
Lucky for us, almost all the recent quakes out here were tiny and the biggest was way off the coast.
```{r}
summary(eq[eq$Region %in% westcoast,'Magnitude'])
```
There are supposed to be active fault lines here in Seattle and you can see a few little quakes. Down by Mt. St. Helens, they get a few moderately bigger ones. The only tremors *I've* felt recently were contractors doing demolition in my basement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.