Skip to content

Instantly share code, notes, and snippets.

@bharatbhole
bharatbhole / RDateSequenceLength.R
Created December 28, 2011 15:40
R - create a sequence of dates of a given length
# Start date: January 5, 2011. Number of days: 45
dates <- seq(as.Date("2011-01-05"), by=1, len=45)
@bharatbhole
bharatbhole / RDateSequenceStartEnd.R
Created December 28, 2011 15:49
Sequence of dates in R with a start date and an end date
# Start date: January 5, 2011. End date: March 15, 2011
dates <- seq(as.Date("2011-01-05"), as.Date("2011-03-15"), by=1)
@bharatbhole
bharatbhole / d3js_make_svgGroups.html
Created January 14, 2012 04:53
d3js_make_svgGroups
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<title>Creating SVG groups with D3.js</title>
</head>
<body>
<div id="d3group"></div>
<script type="text/javascript">
<div id="svgpathSVGdata"></div>
<script type="text/javascript">
var divElem = d3.select("#svgpathSVGdata");
var svgcanvas = divElem.append("svg:svg")
.attr("width", 200)
.attr("height", 200);
// (1) Specifying path data the SVG way
<div id="svgpathSVGdata"></div>
<script type="text/javascript">
var divElem = d3.select("#svgpathSVGdata");
var svgcanvas = divElem.append("svg:svg")
.attr("width", 200)
.attr("height", 200);
// (1) Specifying path data the SVG way
@bharatbhole
bharatbhole / svgpathD3data.html
Created January 14, 2012 19:27
svgpathD3data
<script type="text/javascript">
var divElem2 = d3.select("#svgpathD3data");
svgcanvas2 = divElem2.append("svg:svg")
.attr("width", 200)
.attr("height", 200)
// (2) Creating path using D3 path data generators
@bharatbhole
bharatbhole / loadLib_createData.R
Created February 4, 2012 03:28
load ggplot2 and create data
# load ggplot2 library
require(ggplot2)
# create data
normalVariate <- rnorm(50, 100, 10)
xvalues <- c(1:50)
df <- data.frame(xcol=xvalues, ycol=normalVariate)
@bharatbhole
bharatbhole / basicPlot_defaultOptions.R
Created February 4, 2012 03:30
basic plot default options
# Plot normalVariate data in data frame, df, using ggplot2
# Most basic plot without customizing any options.
plt <- ggplot() + geom_line(data=df, aes(x=xcol, y=ycol))
print(plt)
@bharatbhole
bharatbhole / plotWithCustomAxisLabels.R
Created February 4, 2012 12:50
customize axes labels
# Line plot with custom title for the x-axis (observations) and
# y-axis (Value)
plt <- ggplot() + geom_line(data=df, aes(x=xcol, y=ycol)) +
xlab("Observation") +
ylab("Value")
print(plt)
@bharatbhole
bharatbhole / plotWithCustomLineColorAndSize.R
Created February 4, 2012 13:08
custom color and thickness of the plotted line
# Line plot with custom color and thickness for the plotted line
plt <- ggplot() + geom_line(data=df, aes(x=xcol, y=ycol),
color='steelblue',
size=1)
print(plt)