#install.packages("mapproj") #install.packages("ggmap")
#install.packages("DeducerSpatial") #install.packages("leaflet")
dfv = read.csv("volcano.csv", header=TRUE) # volcano data
dfqb = read.csv("quakes_past_10_year_gt_60.csv", header=TRUE) #quake data

Data

Analysis

we analyze following 3 way relation

  1. Visualize the relationship between volcanoes and earthquakes.
  1. Earthquake magnitude as a function of distance from equator (0° latitude) and the prime meridian (0° longitude) and its epicenter depth
  1. Earthquake magnitude as a function of longitude or latitude.
library(geosphere)
library(ggplot2)
library(leaflet)
library(gridExtra)
library(data.table)
dfqb$depthColor = cut(dfqb$depth, seq(from = min(dfqb$depth)-1, to = max(dfqb$depth)+1,
                                      length.out= 4))
dfqb$magfact = cut(dfqb$mag, seq(from = min(dfqb$mag)-1, to = max(dfqb$mag)+1, 
                                 length.out= 3))
levels(dfqb$magfact) = c("green", "blue")
p1 = ggplot(dfqb) + geom_point(aes(x=longitude,y=mag,color=dfqb$depthColor))
p2 = ggplot(dfqb) + geom_point(aes(x=latitude,y=mag,color=dfqb$depthColor))
dfqb$distHaversinedistfrom00 = distHaversine(matrix(c(dfqb$longitude,
                                             dfqb$latitude),ncol=2),
                                             matrix(c(rep(0,each=length(dfqb$longitude)),                                                                                        rep(0,each=length(dfqb$longitude))), ncol = 2))
p3 = ggplot(dfqb) + geom_point(aes(x=distHaversinedistfrom00,y=mag))
grid.arrange(p1,p2,p3,ncol=1)

# Leaflet map
leaflet(dfqb) %>%
      addTiles() %>%  # Add default OpenStreetMap map tiles
      addCircleMarkers(lat=dfqb$latitude, lng=dfqb$longitude, popup=dfqb$time,
                 fillOpacity = 0.1,color= dfqb$magfact,weight = 3, radius=2) %>%
      addCircleMarkers(lat=dfv$Latitude, lng=dfv$Longitude,  weight = 3, radius=2,
                       popup=dfv$VolcanoName,color="red", stroke = FALSE, fillOpacity = 0.8) 

References

volcanoes data

http://bit.ly/2mzyXwk

earthquake data

https://earthquake.usgs.gov/earthquakes/search/