title: “CumRamphs” author: “Maria Fang” date: “March 10, 2015” output: html_document —
devtools::install_github('rstudio/leaflet')
## Downloading github repo rstudio/leaflet@master
## Installing leaflet
## '/Library/Frameworks/R.framework/Resources/bin/R' --vanilla CMD INSTALL \
## '/private/var/folders/kg/fl91sxkj26g06vwhwzw_kwyh0000gn/T/RtmpYQFlUo/devtools22a421c104/rstudio-leaflet-c9be51e' \
## --library='/Users/mariafang/Library/R/3.1/library' --install-tests
devtools::install_github(c("ramnathv/htmlwidgets", "rstudio/dygraphs"))
## Downloading github repo ramnathv/htmlwidgets@master
## Installing htmlwidgets
## '/Library/Frameworks/R.framework/Resources/bin/R' --vanilla CMD INSTALL \
## '/private/var/folders/kg/fl91sxkj26g06vwhwzw_kwyh0000gn/T/RtmpYQFlUo/devtools22a45ede0d62/ramnathv-htmlwidgets-921ba80' \
## --library='/Users/mariafang/Library/R/3.1/library' --install-tests
##
## Downloading github repo rstudio/dygraphs@master
## Installing dygraphs
## '/Library/Frameworks/R.framework/Resources/bin/R' --vanilla CMD INSTALL \
## '/private/var/folders/kg/fl91sxkj26g06vwhwzw_kwyh0000gn/T/RtmpYQFlUo/devtools22a47a7955db/rstudio-dygraphs-d378ed7' \
## --library='/Users/mariafang/Library/R/3.1/library' --install-tests
require(curl)
## Loading required package: curl
require(DT)
## Loading required package: DT
require(jsonlite)
## Loading required package: jsonlite
##
## Attaching package: 'jsonlite'
##
## The following object is masked from 'package:utils':
##
## View
require(rgdal)
## Loading required package: rgdal
## Loading required package: sp
## rgdal: version: 0.9-1, (SVN revision 518)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 1.9.2, released 2012/10/08
## Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rgdal/gdal
## Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
## Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rgdal/proj
require(plyr)
## Loading required package: plyr
require(sp)
require(zoo)
## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
require(leaflet)
## Loading required package: leaflet
require(maps)
## Loading required package: maps
require(devtools)
## Loading required package: devtools
require(dygraphs)
## Loading required package: 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")
## Warning: Unexpected Content-Type: text/plain
# 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)
## OGR data source with driver: GeoJSON
## Source: "https://gist.githubusercontent.com/sfsheath/7726c6f5fff9aa45ee15/raw/c828e6a3182bc1058b6cee1788a8e58e2dbc5aad/rome200.geojson", layer: "OGRGeoJSON"
## with 112 features and 8 fields
## Feature type: wkbMultiPolygon with 2 dimensions
# 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()
## Warning in zoo((ramphs.positive$capacity), x.Date): some methods for "zoo"
## objects do not work if the index entries in 'order.by' are not unique