Stackoverflow question: http://stackoverflow.com/questions/32549683/d3js-json-pie-chart?noredirect=1#comment52995750_32549683
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"> | |
<canvas style="width:100%; height:100%"></canvas> | |
<script> | |
/* https://github.com/d3/d3-timer Copyright 2015 Mike Bostock */ | |
"undefined"==typeof requestAnimationFrame&&(requestAnimationFrame="undefined"!=typeof window&&(window.msRequestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.oRequestAnimationFrame)||function(e){return setTimeout(e,17)}),function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.timer={})}(this,function(e){"use strict";function n(){r=m=0,c=1/0,t(u())}function t(e){if(!r){var t=e-Date.now();t>24?c>e&&(m&&clearTimeout(m),m=setTimeout(n,t),c=e):(m&&(m=clearTimeout(m),c=1/0),r=requestAnimationFrame(n))}}function i(e,n,i){i=null==i?Date.now():+i,null!=n&&(i+=+n);var o={callback:e,time:i,flush:!1,next:null};a?a.next=o:f=o,a=o,t(i)}function o(e,n,t){t=null==t?Date.now():+t,null!=n&&(t+=+n),l.callback=e,l.time=t}function u(e){e=nu |
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
# r doesn't have a standard error function | |
stderr = function(x) sqrt(var(x,na.rm=TRUE)/length(na.omit(x))) | |
ci = function(x, confidence.interval=0.95) stderr(x) * qnorm(1 - (1-confidence.interval)/2) |
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> | |
<html> | |
<body> | |
<canvas id="myCanvas" width="1000" height="1000"></canvas> | |
<script> | |
function drawImage() { | |
var canvas = document.getElementById('myCanvas'); | |
var context = canvas.getContext('2d'); | |
var imageWidth = canvas.width = Math.min(canvas.width, window.innerWidth); | |
var imageHeight = canvas.height = Math.min(canvas.height, window.innerHeight); |
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
library(ggplot2) | |
yDistribution <- function(x) { return(1/x) } | |
xSampleDistribution <- function(x) { return((2 ^ x) * 10) } | |
x <- c() | |
y <- c() | |
for (i in 0:8) { | |
sampleCount <- xSampleDistribution(i) | |
x <- c(x, rep(i, sampleCount)) |
This simple bar chart is constructed from a TSV file storing the frequency of letters in the English language. The chart employs conventional margins and a number of D3 features:
- d3.tsv - load and parse data
- d3.format - format percentages
- d3.scale.ordinal - x-position encoding
- d3.scale.linear - y-position encoding
- d3.max - compute domains
- d3.svg.axis - display axes
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
install.packages('Cairo') | |
install.packages('data.table') | |
install.packages('extrafont') | |
install.packages('ggplot2') | |
install.packages('lubridate') | |
install.packages('plyr') | |
install.packages('dplyr') | |
install.packages('rjson') | |
install.packages('stringr') | |
install.packages('XML') |
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
Year,Make,Model,Length | |
1997,Ford,E350,2.34 | |
2000,Mercury,Cougar,2.38 |
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
mydate1 = as.Date("2000-01-01") | |
mydate2 = as.Date("2000-03-01") | |
# EASY: sequence with every other int | |
seq(1, 60, by=2) | |
# HARD: sequence with every other day | |
seq(mydate1, mydate2, by=???) # day? | |
# pretend you're new to R | |
# you don't know about lubridate or POSIX |