Last active
August 29, 2015 14:16
-
-
Save marsimaria/12e5a2899c73765b999b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mapping Roman Amphitheater data | |
## Time series plots of capacity & extmajor. Leaflet with both the outline of the roman empire & locations of amphitheaters. And testing htmlwidget with ramphs capacity. | |
--- | |
title: "CumRamphs" | |
author: "Maria Fang" | |
date: "March 10, 2015" | |
output: html_document | |
--- | |
```{r plot} | |
devtools::install_github('rstudio/leaflet') | |
devtools::install_github(c("ramnathv/htmlwidgets", "rstudio/dygraphs")) | |
require(curl) | |
require(DT) | |
require(jsonlite) | |
require(rgdal) | |
require(plyr) | |
require(sp) | |
require(zoo) | |
require(leaflet) | |
require(maps) | |
require(devtools) | |
require(dygraphs) | |
ramphs <- read.csv(curl("https://gist.githubusercontent.com/sfsheath/5c5987269e8aad412416/raw/a12dda2b8a681f1ab01421f68ac237ab591ff0f9/roman-amphitheaters.csv")) | |
periods <- fromJSON("https://gist.githubusercontent.com/sfsheath/cc082cc6db3ac8343e3a/raw/6e938ed37b9083f393a67bec10b46ba7fc693661/amphitheater-chronogrps.json") | |
# ramphsDates is main file do not change! | |
join(ramphs, periods, by="chronogrp") -> ramphsDates | |
# get roman empire outline | |
roman.outline <- readOGR("https://gist.githubusercontent.com/sfsheath/7726c6f5fff9aa45ee15/raw/c828e6a3182bc1058b6cee1788a8e58e2dbc5aad/rome200.geojson", layer="OGRGeoJSON", disambiguateFIDs = T) | |
# zoo plots! save in new file | |
ramphsDates -> ramphs.100 | |
# add 100 to each start_date to make them positive numbers for R to read | |
ramphs.100$start_date <- sprintf("%s", ramphs.100$start_date+100) | |
# add -01-01 into every start_date to be plottable | |
ramphs.100$start_date <- sprintf("%s-01-01", ramphs.100$start_date) | |
# define x.Date as an object and not vector to be used in zoo | |
x.Date <- as.Date(ramphs.100$start_date) | |
# Replace all NA value to 0 to be plottable | |
ramphs.100 -> ramphs.positive | |
ramphs.positive$capacity[is.na(ramphs.positive$capacity)] <- 0 | |
ramphs.positive$extmajor[is.na(ramphs.positive$extmajor)] <- 0 | |
# plot zoo object of each variable | |
plot(cumsum(zoo((ramphs.positive$capacity), x.Date))) | |
plot(cumsum(zoo((ramphs.positive$extmajor), x.Date))) | |
#plot(cumsum(zoo((ramphs.positive$elevation), x.Date))) | |
# leaflet! save new object | |
ramphsDates -> ramphsLoc | |
# get coordinates to map | |
# coordinates(ramphsLoc) <-~latitude + longitude | |
# plot roman empire outline | |
# plot(roman.outline, col="gray", border="blue", axes=TRUE, pbg="white") | |
# leaflet each amphitheater at the right location | |
m <- leaflet(ramphsLoc) %>% addTiles() | |
m %>% addPolylines(data = roman.outline, color = "red", weight = 4) %>% addCircles(lat = ~ latitude, lng = ~ longitude) | |
# htmlwidgets | |
dygraph(cumsum(zoo((ramphs.positive$capacity), x.Date))) %>% dyAxis("y", label = "capacity") %>% dyOptions(fillGraph = TRUE, drawGrid = FALSE) %>% dyRangeSelector() | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment