Skip to content

Instantly share code, notes, and snippets.

Avatar

Ramnath Vaidyanathan ramnathv

View GitHub Profile
@ramnathv
ramnathv / code.R
Created Jan 29, 2014
My First rChart
View code.R
library(rCharts)
r1 <- rPlot(mpg ~ wt, data = mtcars, type = 'point')
r1
View README.md

This hexbin map shows the proximity of earthquakes (magnitude 3.0 or greater) in the Canterbury region of New Zealand during the month of September, 2010.

The map is created using Leaflet. The hexbin layer is a custom Leaflet layer which uses d3js to generate a svg hexbin overlay. The source for the custom leaflet layer is viewable here.

Earthquake data sourced from GeoNet.

@ramnathv
ramnathv / code.R
Created Feb 5, 2014
Scatter Matrix (Courtesy: JH)
View code.R
# Get Data
library(RCurl)
f <- getURL("https://raw.github.com/benjh33/benjh33.github.io/cd768434d02b39b01615d03f04a68b0fe33eb76e/_data/data_files/electric.dat")
d <- read.table(text = f, header = T)
d <- d[, -grep("Supplement", names(d))]
# Create Chart
chart <- rCharts$new()
chart$setLib("http://benjh33.github.io/rchart_plugins/scatter_matrix")
chart$set(
@ramnathv
ramnathv / index.html
Created Feb 5, 2014
Pie Charts with NVD3 Controls
View index.html
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<link rel='stylesheet' href='http://nvd3.org/src/nv.d3.css'>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' type='text/javascript'></script>
<script src='http://d3js.org/d3.v3.min.js' type='text/javascript'></script>
<script src='http://timelyportfolio.github.io/rCharts_nvd3_tests/libraries/widgets/nvd3/js/nv.d3.min-new.js' type='text/javascript'></script>
View stringify.js
var stringify = function(obj, prop) {
var placeholder = '____PLACEHOLDER____';
var fns = [];
var json = JSON.stringify(obj, function(key, value) {
if (typeof value === 'function') {
fns.push(value);
return placeholder;
}
return value;
}, 2);
@ramnathv
ramnathv / index.html
Created Feb 10, 2014
Publishing from rMaps
View index.html
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href='http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.css'>
<script src='http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.js' type='text/javascript'></script>
<script src='https://rawgithub.com/leaflet-extras/leaflet-providers/gh-pages/leaflet-providers.js' type='text/javascript'></script>
<script src='http://harrywood.co.uk/maps/examples/leaflet/leaflet-plugins/layer/vector/KML.js' type='text/javascript'></script>
@ramnathv
ramnathv / index.html
Created Feb 12, 2014
Slidify with Standalone HTML
View index.html
This file has been truncated, but you can view the full file.
<!DOCTYPE html>
<html>
<head>
<title>Standalone HTML</title>
<meta charset="utf-8">
<meta name="description" content="Standalone HTML">
<meta name="author" content="">
<meta name="generator" content="slidify" />
<meta name="apple-mobile-web-app-capable" content="yes">
@ramnathv
ramnathv / index.html
Created Feb 12, 2014
Slidify with Standalone HTML
View index.html
This file has been truncated, but you can view the full file.
<!DOCTYPE html>
<html>
<head>
<title>Standalone HTML</title>
<meta charset="utf-8">
<meta name="description" content="Standalone HTML">
<meta name="author" content="">
<meta name="generator" content="slidify" />
<meta name="apple-mobile-web-app-capable" content="yes">
View README.md

This is a rewrite of the mapping code used in this post by Diego Valle. It basically replaces all the boilerplate code with the ichoropleth function in rMaps, which wraps it, allowing easier reuse. Please follow the code from the original post to the get the shapefiles, topojson and data. My note will start with the dataset hom.

d1 <- ichoropleth(rate ~ name, data = hom, ncuts = 9, pal = 'YlOrRd', 
  animate = 'year',  map = 'states'
)
d1$set(
  geographyConfig = list(
   dataUrl = "mx_states.json"
  ),
View mymap.html
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<script src='http://cdnjs.cloudflare.com/ajax/libs/headjs/1.0.3/head.min.js' type='text/javascript'></script>
<style>
.rChart {
display: block;
You can’t perform that action at this time.