This file contains hidden or 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
# We only need the columns with the latitude and longitude | |
coords <- stops[c("InterventionLocationLongitude", "InterventionLocationLatitude")] | |
# Making sure we are working with rows that don't have any blanks | |
coords <- coords[complete.cases(coords),] | |
library(sp) | |
# Letting R know that these are specifically spatial coordinates | |
sp <- SpatialPoints(coords) |
This file contains hidden or 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
# Bring in the shape files for census tracts | |
require(rgdal) | |
# dsn is the folder the shape files are in. layer is the name of the file. | |
towntracts <- readOGR(dsn="shapes", layer="census_tracts") | |
# creating a copy | |
towntracts_only <- towntracts |
This file contains hidden or 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
# Bring in the data | |
stops <- read.csv("https://github.com/trendct/walkthroughs/raw/master/spatial-analysis-r-walkthrough/data/hamden_stops.csv", stringsAsFactors=FALSE) | |
# Check and eliminate the rows that don't have location information | |
stops <- stops[!is.na(stops$InterventionLocationLatitude),] | |
# Add a column to identifying a driver as white or a minority | |
stops$ethnicity <- ifelse(((stops$SubjectRaceCode == "W") & (stops$SubjectEthnicityCode =="N")), "White", "Minority") |
This file contains hidden or 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
# create the pop-up info | |
beer_advocate$pop_up_content <- paste(sep = "<br/>", | |
"<b><a href='", beer_advocate$beer_advocate_website, "'>", beer_advocate$brewery_name, "</a></b>", beer_advocate$address, | |
beer_advocate$phone_number, paste("Average beer rating: ", beer_advocate$beer_avg,"/5.0")) | |
# add colors corresponding to the average beer ratings | |
pal <- colorNumeric("YlOrRd", beer_advocate$beer_avg, n = 6) | |
m <- leaflet(data = beer_advocate) %>% | |
addTiles() %>% |
This file contains hidden or 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
library(htmlwidgets) | |
library(leaflet) | |
library(ggmap) | |
# This function geocodes a location (find latitude and longitude) using the Google Maps API | |
geo <- geocode(location = beer_advocate$address, output="latlon", source="google") | |
# add those coordinates to our dataset | |
beer_advocate$lon <- geo$lon | |
beer_advocate$lat <- geo$lat |
This file contains hidden or 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
# remove duplicate columns with unimportant info | |
beer_advocate$bottomdark_links._text <- NULL | |
beer_advocate$bottomdark_links._source <- NULL | |
beer_advocate$pageUrl <- NULL | |
beer_advocate$image <- NULL | |
beer_advocate$bottomdark_content_numbers._source <- NULL | |
beer_advocate$bottomlight_number <- NULL | |
beer_advocate$link._source <- NULL | |
# change the column names |
This file contains hidden or 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
beer_advocate <- read.csv("beeradvocate.com API 14th Dec 10-37.csv") | |
beer_head <- head(beer_advocate) |
This file contains hidden or 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
<!doctype html> | |
<meta charset="utf-8"> | |
<!-- Load d3.js --> | |
<script src="http://www.d3plus.org/js/d3.js"></script> | |
<!-- Load d3plus.js --> | |
<script src="http://www.d3plus.org/js/d3plus.js"></script> | |
<div id="viz"></div> |
This file contains hidden or 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
<!doctype html> | |
<meta charset="utf-8"> | |
<!-- Load d3.js --> | |
<script src="http://www.d3plus.org/js/d3.js"></script> | |
<!-- Load d3plus.js --> | |
<script src="http://www.d3plus.org/js/d3plus.js"></script> | |
<div id="viz"></div> |
This file contains hidden or 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
<html> | |
<head> | |
<title>Highcharts Tutorial</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script src="http://code.highcharts.com/highcharts.js"></script> | |
</head> | |
<body> | |
<div id="container" style="width: 550px; height: 400px; margin: 0 auto"></div> | |
<script language="JavaScript"> | |
$(document).ready(function() { |