Skip to content

Instantly share code, notes, and snippets.

@dashalom
Created March 11, 2015 12:48
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 dashalom/ccc93064e1193599a288 to your computer and use it in GitHub Desktop.
Save dashalom/ccc93064e1193599a288 to your computer and use it in GitHub Desktop.
Homework March 11
---
title: "Homework"
author: "Dalit Shalom"
date: "March 10, 2015"
output: html_document
---
```{r}
#---loading the initial data here that I will need in order to run the data from R---
#Libraries:
require(curl)
require(jsonlite)
require(rgdal)
require(plyr)
require(zoo)
require(dygraphs)
library(knitr)
require (DT)
require(leaflet)
require(sp)
#Loading the dataset
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")
ramphs.sp <- ramphs
join(ramphs.sp, periods, by= "chronogrp") -> ramphs.joined
coordinates(ramphs.joined) <- ~longitude + latitude
ramphs.noise <- ramphs.joined
tmp.length <- length(ramphs.noise$start_date[ramphs.noise$chronogrp=="Imperial"])
tmp.min <- min(ramphs.noise$start_date[ramphs.noise$chronogrp=="Imperial"])
tmp.max <- max(ramphs.noise$end_date[ramphs.noise$chronogrp=="Imperial"])
ramphs.noise$start_date[ramphs.noise$chronogrp=="Imperial"] <- runif(tmp.length,
min=tmp.min,
max=tmp.max)
round(ramphs.noise$start_date, digits=0) -> ramphs.noise$start_date
#--------------#
#Everything is loaded, time to start:
#First, I am going to plot the relationship between years and cumulative capacity
#I moved all the data back from "ramphs.noise" to the "ramphs.joined" object
ramphs.noise -> ramphs.joined
#I made a copy of that here
ramphs.joined -> ramphs.joined.date
#I added 100 to all of the years in "start_date" so that none of them would be negative
sprintf("%s", ramphs.joined.date$start_date + 100) -> ramphs.joined.date$start_date
#Then I added month and days to those years
ramphs.joined.date$start_date <- sprintf("%s-01-01", ramphs.joined.date$start_date)
#make a zoo x.Date object
x.Date <- as.Date(ramphs.joined.date$start_date)
#make another copy of the main dataset
ramphs.joined -> ramphs.joined.capacity
#asign 0 to all the NA in "capacity"
ramphs.joined.capacity$capacity[is.na(ramphs.joined.capacity$capacity)] <- 0
#plot graph of relationship between years and cumulative capacity
plot(cumsum(zoo((ramphs.joined.capacity$capacity), x.Date)))
#and -- DYGRAPHS + SELECTORS!
dygraph(cumsum(zoo((ramphs.joined.capacity$capacity), x.Date)))%>%
dyRangeSelector(dateWindow = c("0-01-01", "300-01-01"))
###########
#Second, I am going to plot the relationship between years and extmajor which is the major length of the amphitheaters
#I already have the "x.Date" object from before, so:
#make a copy of the original dataset
ramphs.joined -> ramphs.joined.extmajor
#asign 0 to all the NA in "extmajor"
ramphs.joined.extmajor$extmajor[is.na(ramphs.joined.extmajor$extmajor)] <- 0
#plot graph of relationship between years and cumulative capacity
plot(cumsum(zoo((ramphs.joined.extmajor$extmajor), x.Date)))
#---TRY THIS LATER--plot(cumsum(zoo((ramphs.joined$extmajor[ramphs.joined$modcountry==Italy]), x.Date)))
#and -- DYGRAPHS + SELECTORS!
dygraph(cumsum(zoo((ramphs.joined.extmajor$extmajor), x.Date)))%>%
dyRangeSelector(dateWindow = c("0-01-01", "300-01-01"))
#Now, more cumulative experiments!
#Let's see the relationship between years and cumulative population:
#make a copy of the original dataset
ramphs.joined -> ramphs.joined.population
#asign 0 to all the NA in "population"
ramphs.joined.population$population[is.na(ramphs.joined.population$population)] <- 0
#plot graph of relationship between years and cumulative capacity
plot(cumsum(zoo((ramphs.joined.population$population), x.Date)))
#and -- DYGRAPHS + SELECTORS!
dygraph(cumsum(zoo((ramphs.joined.population$population), x.Date)))%>%
dyRangeSelector(dateWindow = c("0-01-01", "300-01-01"))
#----LEAFLET----#
mapoutline <- readOGR("https://gist.githubusercontent.com/sfsheath/7726c6f5fff9aa45ee15/raw/c828e6a3182bc1058b6cee1788a8e58e2dbc5aad/rome200.geojson", layer="OGRGeoJSON", disambiguateFIDs = T)
plot(mapoutline)
plot(ramphs.joined, add = T) #add the amphitheater data over the mapoutline
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment