Skip to content

Instantly share code, notes, and snippets.

View ramnathv's full-sized avatar

Ramnath Vaidyanathan ramnathv

View GitHub Profile
to_geo_json <- function(x, ...){
UseMethod('to_geo_json')
}
to_geo_json.data.frame <- function(x, lat = "latitude", lon = "longitude"){
geo_json = vector('list', NROW(x))
y = lapply(1:NROW(x), function(i){
if (is.null(x[i,lat]) || is.null(x[i,lon])){
return(NULL)
} else {
@ramnathv
ramnathv / README.md
Last active August 29, 2015 13:58
Building an rCharts Library

I very frequently get asked this question as to what is the best way to get started with building an rCharts library. While rCharts ships with its own bindings, I tend to see it more as a framework that allows one to seamlessly plug into other javascript visualization libraries, or even custom visualizations for that matter.

I will be writing a more detailed developer guide on how to build rCharts bindings for a library or chart of interest. For now, the knowledge is scattered across blog posts and my objective here is to consolidate them to provide some structure for anyone trying to build their own binding.

I will start with two posts of my own, where I deconstruct the process of going from a javascript visualization library to an rCharts binding. I take the example of uvCharts, which is a wrapper around d3.js, and explain how to go about integrating it within the rCharts framework.

  • [How rCharts Works -
@ramnathv
ramnathv / rmagic.md
Last active August 29, 2015 13:59
Using Rmagic with IPython

Rmagic allows R commands to be executed from within an IPython notebook. In addition, it also provides a mechanism to exchange data with Python. You will need to install the rpy2 package to use Rmagic. Here are some resources that should help get you started.

  1. rmagic
  2. Rmagic Functions Extension
# install.packages("Lahman")
data(Teams, package = "Lahman")
library(ggplot2)
plot_team <- function(teamID){
p0 <- ggplot() +
geom_point(
mapping = aes(
x = yearID,
y = SO/G
),
@ramnathv
ramnathv / index.html
Created April 25, 2014 11:48
Hair vs. Eye Color
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href='http://nvd3.org/assets/css/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>
<script src='http://nvd3.org/assets/lib/fisheye.js' type='text/javascript'></script>
@ramnathv
ramnathv / index.html
Created April 25, 2014 18:12
Hair vs. Eye Color
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href='http://nvd3.org/assets/css/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>
<script src='http://nvd3.org/assets/lib/fisheye.js' type='text/javascript'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Notebook</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ramnathv
ramnathv / index.html
Created May 9, 2014 00:23
Hair Color vs. Eye Color
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href='http://nvd3.org/assets/css/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>
<script src='http://nvd3.org/assets/lib/fisheye.js' type='text/javascript'></script>
@ramnathv
ramnathv / code.R
Created May 9, 2014 00:28
My Second Chart
library(rCharts)
hair_eye_male = subset(
as.data.frame(HairEyeColor),
Sex == "Male"
)
n1 <- nPlot(Freq ~ Hair,
group = 'Eye',
data = hair_eye_male,
type = 'multiBarChart'
)