Skip to content

Instantly share code, notes, and snippets.

@achubaty
Last active October 6, 2015 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achubaty/fe3d6481f152bb14cec4 to your computer and use it in GitHub Desktop.
Save achubaty/fe3d6481f152bb14cec4 to your computer and use it in GitHub Desktop.
library(mapproj)
library(rgdal)
## view the original data & ggplot map from
## http://rud.is/b/2015/10/04/replicating-natgeos-proper-earthquake-map-in-r/
url <- "http://rud.is/dl/quakefile.tgz"
if (!file.exists(basename(url))) {
download.file(url, destfile = basename(url))
untar(basename(url))
}
world <- readOGR("countries.geo.json", "OGRGeoJSON", stringsAsFactors=FALSE)
plates <- readOGR("plates.json", "OGRGeoJSON", stringsAsFactors=FALSE)
quakes <- readOGR("quakes.json", "OGRGeoJSON", stringsAsFactors=FALSE)
world_map <- fortify(world)
plates_map <- fortify(plates)
quakes_dat <- data.frame(quakes)
quakes_dat$trans <- quakes_dat$mag %% 5
## shiny + leaflet version
library(leaflet)
library(shiny)
leaflet() %>% addTiles() %>%
addPolygons(data = plates, popup = plates$PLATE,
color = "black", weight = 1, fillColor = "#00000000") %>%
addCircleMarkers(lng = quakes_dat$coords.x1, lat = quakes_dat$coords.x2,
radius = quakes_dat$mag, popup = quakes_dat$title,
color = "#d47e5d")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment