USGS Earthquake Map

require("knitr")
## Loading required package: knitr
knitr::opts_chunk$set(echo = TRUE)
opts_knit$set(root.dir = "~/Documents/Data Science/Maps")

1. Synopsis

This script collects the data from the USGS Earthquake repository, data that dates back to 1900 to date, and maps all points in different maps.

Load Libraries

library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(devtools)
library(stringr)
library(maps)
library(mapdata)
library(ggmap)

2. Data Processing

## Setup working directory
setwd("~/Documents/Data Science/Maps")

## Table load
EarthQuakeData <-read.csv("all_month.csv", header=TRUE, sep=",", na.strings = "NA")

2.1.1 System Information

Sys.info()
##                                                                                           sysname 
##                                                                                          "Darwin" 
##                                                                                           release 
##                                                                                          "15.6.0" 
##                                                                                           version 
## "Darwin Kernel Version 15.6.0: Tue Jan  9 20:12:05 PST 2018; root:xnu-3248.73.5~1/RELEASE_X86_64" 
##                                                                                          nodename 
##                                                                         "Joses-MacBook-Pro.local" 
##                                                                                           machine 
##                                                                                          "x86_64" 
##                                                                                             login 
##                                                                                          "josepi" 
##                                                                                              user 
##                                                                                          "josepi" 
##                                                                                    effective_user 
##                                                                                          "josepi"

2.1 Structure of Storm Data File

str(EarthQuakeData)
## 'data.frame':    9442 obs. of  22 variables:
##  $ time           : Factor w/ 9442 levels "2018-01-27T03:52:44.750Z",..: 9442 9441 9440 9439 9438 9437 9436 9435 9434 9433 ...
##  $ latitude       : num  38.83 38.82 -6.12 -6.3 63.55 ...
##  $ longitude      : num  -123 -123 143 143 -151 ...
##  $ depth          : num  2 1.87 35 35 8.7 ...
##  $ mag            : num  1.16 1.46 5.2 5 1.2 4.8 5 1.1 1.12 0.56 ...
##  $ magType        : Factor w/ 9 levels "","mb","mb_lg",..: 4 4 2 2 6 2 2 6 4 4 ...
##  $ nst            : int  17 23 NA NA NA NA NA 21 17 6 ...
##  $ gap            : num  49 79 50 72 NA ...
##  $ dmin           : num  0.01056 0.00498 5.24 5.167 NA ...
##  $ rms            : num  0.03 0.04 0.94 0.81 0.64 ...
##  $ net            : Factor w/ 14 levels "ak","ci","hv",..: 7 7 12 12 1 12 12 9 7 7 ...
##  $ id             : Factor w/ 9442 levels "ak18205098","ak18205146",..: 6477 6476 8874 8873 2895 8872 8871 7405 6475 6474 ...
##  $ updated        : Factor w/ 9442 levels "2018-01-27T04:03:40.348Z",..: 9441 9442 9439 9440 9427 9432 9426 9436 9437 9430 ...
##  $ place          : Factor w/ 5403 levels "0km E of Jauca, Puerto Rico",..: 4787 5318 4446 4605 5213 3352 4647 390 3481 3481 ...
##  $ type           : Factor w/ 5 levels "chemical explosion",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ horizontalError: num  0.24 0.23 5 4.8 NA 9.6 8.1 NA 0.3 0.58 ...
##  $ depthError     : num  0.4 0.34 1.9 1.9 0.2 2.8 1.9 1.6 0.58 0.99 ...
##  $ magError       : num  0.09 0.12 0.054 0.092 NA 0.124 0.065 0.28 0.11 NA ...
##  $ magNst         : int  5 6 114 38 NA 20 76 7 5 1 ...
##  $ status         : Factor w/ 2 levels "automatic","reviewed": 1 1 2 2 1 2 2 2 1 1 ...
##  $ locationSource : Factor w/ 16 levels "ak","ci","hv",..: 7 7 14 14 1 14 14 9 7 7 ...
##  $ magSource      : Factor w/ 18 levels "ak","buc","ci",..: 9 9 16 16 1 16 16 11 9 9 ...

3. Map the data

3.1 Draw the map

world <- map_data("world")
gg1 <- ggplot() +
        geom_polygon(data = world, aes(x=long, y =lat, group = group), fill = "green", color = "blue") +
        coord_fixed(1.3)
gg1

3.2 Add the data points

gg1 +
        geom_point(data = EarthQuakeData, aes(x = EarthQuakeData$longitude, y = EarthQuakeData$latitude), color = "black", size = 5) +
        geom_point(data = EarthQuakeData, aes(x = EarthQuakeData$longitude, y = EarthQuakeData$latitude), color = "yellow", size = 4) +
        ggtitle("USGS Earthquake Data - Last 30 Days") +
        labs(x = "Longitude", y = "Latitude")