install.packages("leaflet")
## package 'leaflet' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\udy140\AppData\Local\Temp\RtmpaMHO2J\downloaded_packages
library("leaflet")
The Department of Geophysics at Harvard University collected 1000 seismic events of MB>4.0 that occured near Fiji. For this project, all the coordinates and Ritcher magnitudes are used to create an interactive map.
This dataset is one of the Havard PRIM-H project data sets. It has been has been loaded into R in csv format. The dataset gives the locations of 1,000 seismic events of MB>4.0. The events occurred in a cube near Fiji since 1964. There are two clear planes of semismic activity. One is a major plate junction; the other is the Tonga trench off New Zealand. These data constitute a subsample from a larger dataset containing 5,000 observations.
quakes<-read.csv("https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/datasets/quakes.csv")
summary(quakes)
## X lat long depth
## Min. : 1.0 Min. :-38.59 Min. :165.7 Min. : 40.0
## 1st Qu.: 250.8 1st Qu.:-23.47 1st Qu.:179.6 1st Qu.: 99.0
## Median : 500.5 Median :-20.30 Median :181.4 Median :247.0
## Mean : 500.5 Mean :-20.64 Mean :179.5 Mean :311.4
## 3rd Qu.: 750.2 3rd Qu.:-17.64 3rd Qu.:183.2 3rd Qu.:543.0
## Max. :1000.0 Max. :-10.72 Max. :188.1 Max. :680.0
## mag stations
## Min. :4.00 Min. : 10.00
## 1st Qu.:4.30 1st Qu.: 18.00
## Median :4.60 Median : 27.00
## Mean :4.62 Mean : 33.42
## 3rd Qu.:4.90 3rd Qu.: 42.00
## Max. :6.40 Max. :132.00
str(quakes)
## 'data.frame': 1000 obs. of 6 variables:
## $ X : int 1 2 3 4 5 6 7 8 9 10 ...
## $ lat : num -20.4 -20.6 -26 -18 -20.4 ...
## $ long : num 182 181 184 182 182 ...
## $ depth : int 562 650 42 626 649 195 82 194 211 622 ...
## $ mag : num 4.8 4.2 5.4 4.1 4 4 4.8 4.4 4.7 4.3 ...
## $ stations: int 41 15 43 19 11 12 43 15 35 19 ...
This dataset includes useful information regarding Earthquakes off Fiji: latitude of event, longitude, depth, Richter magnitude, and number of stations reporting. For this project, only the coordinates and Richter Magnitude are used.
Before beginning to plot the data, I wanted to remove any data rows that did not include coordinates.
eliminate <- quakes[!is.na(quakes$long)&!is.na(quakes$lat),]
Since all data rows include coordinates, none of the data was removed.
There are so many points on a map that it doesn’t make sense to see every plot marker available–it would be too crowded to even mess with. So, plots of clusters of markers with addMarkers(clusterOptions = markerClusterOptions()) are used to group them together. You can zoom in to each cluster, the clusters will separate until you can see the individual markers. The Richter magnitude is added as a popup for each marker. Click on any blue marker to determine what the Richter magnitude is for each event.
data(quakes)
leaflet(data=quakes) %>%
addTiles() %>%
addMarkers(
popup=as.character(quakes$mag),
label=as.character(quakes$mag),
clusterOptions = markerClusterOptions()
)
## Assuming "long" and "lat" are longitude and latitude, respectively
In this project Earthquakes around Fiji are displayed using Leaflet, one of the most popular Javascript libraries for creating interactive maps. By zooming in and out of the map, you will be able to see where seimic events of MB>4.0 are located near Fiji and what the Ritcher magnitudes are for each event. With the Leaflet package in R, I was able to create an interactive map without needing to know all the ins-and-outs of Javascript.