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
# Using the fivethirtyeight package | |
library(fivethirtyeight) | |
library(tidyr) | |
library(tibble) | |
library(dplyr) | |
# See names of columns | |
names(murder_2015_final) |
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
# Getting Started with tidyverse in R | |
library(tidyr) | |
library(tibble) | |
key_value <- tribble( | |
~row, ~key1, ~key2, ~key3, # These are the names of the columns (indicated with ~) | |
"1", "1_value_1","1_value_2","1_value_3", # Row 1 | |
"2", "2_value_1", "2_value_2", "2_value_3", # Row 2 | |
"3", "3_value_1", "3_value_2", "3_value_3" # Row 3 |
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
# How to create a line chart in R | |
library(ggplot2) | |
venezuela.data <- read.csv(file="venezuela.csv") | |
p1 <- ggplot() + | |
geom_line(aes(y = units, x = year), data = venezuela.data) + | |
scale_x_continuous(breaks=seq(2002,2016,2)) + | |
theme(text=element_text(family="Tahoma")) |
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
# Geocoding a csv column of "addresses" in R | |
#load ggmap | |
library(ggmap) | |
# Select the file from the file chooser | |
fileToLoad <- file.choose(new = TRUE) | |
# Read in the CSV data and store it in a variable | |
origAddress <- read.csv(fileToLoad, stringsAsFactors = FALSE) |
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
// example coordinates | |
var coords = [34.052108, -118.245678]; | |
var sql = new cartodb.SQL({ user: 'latimes' }); | |
sql.execute("SELECT ST_Distance(the_geom::geography, ST_SetSRID(ST_Point("+ coords[1] +", "+ coords[0] +"),4326)::geography) as fDistance FROM socal_freeways") | |
.done(function(data) { | |
// distance in feet rounded to nearest 10 | |
var distFeet = Math.round((data.rows[0].fdistance * 3.28084)/10)*10; |
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
<figure class="graphic-wrapper"> | |
<h2 class="graphic-hed">Thousands of homes approved near L.A. freeways</h2> | |
<p class="graphic-chatter" style="text-align:center;">Use the slider to see where the city has issued building permits within a 1,000 feet of a freeway since 2005.</p> | |
<h2 id="year-selected">2005</h2> | |
<input type="range" step="0" id="retirement-slider" class="graphic-slider" min="0" max="11" value="0"> | |
<div class="slider-map-container"> | |
<ul class="map-images"> | |
<li><img src="/projects/la-me-freeway-pollution/static/img/timeline-slider-2005-01.png"></li> |
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
/** choropleth visualization */ | |
#clean_merge{ | |
polygon-fill: #FFFFB2; | |
polygon-opacity: 1; | |
line-color: #FFF; | |
line-width: 0; | |
line-opacity: 0; | |
} | |
#clean_merge [ estimated_age_adjusted_death_rate_11_categories_in_ranges <= 20.1] { |
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
function tick(e) { | |
// Push different nodes in different directions for clustering. | |
var k = 6 * e.alpha; | |
nodes.forEach(function(o, i) { | |
o.y += i & 1 ? k : -k; | |
o.x += i & 2 ? k : -k; | |
}); | |
node.attr("cx", function(d) { return d.x; }) |
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<script src="http://d3js.org/d3.v3.js"></script> | |
<style> | |
path.link { | |
fill: none; | |
stroke: #666; | |
stroke-width: 1.5px; | |
} |
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
var attributes = [ | |
{"name": "concussions", "hex": "#0000ff"} | |
] | |
// instantiate d3plus | |
var visualization = d3plus.viz() | |
.container("#viz") // container DIV to hold the visualization | |
.data(sample_data) // data to use with the visualization | |
.type("line") // visualization type | |
.id("name") // key for which our data is unique on |