index.html
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href="//netdna.bootstrapcdn.com/bootswatch/2.3.1/cosmo/bootstrap.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css" >
<link rel='stylesheet' href="//twitter.github.io/bootstrap/assets/js/google-code-prettify/prettify.css">
<link rel='stylesheet' href="//aozora.github.io/bootplus/assets/css/docs.css">
<script src='//d3js.org/d3.v3.min.js' type='text/javascript'></script>
<script src='//dimplejs.org/dist/dimple.v1.min.js' type='text/javascript'></script>
<style>
.rChart {
display: block
margin: auto auto;
width: 100%;
height: 400px;
}
</style>
</head>
<body>
<div class='container'>
<div class='row'>
<div class='span8'>
<div class="bs-docs-example">
<div id='chart1aa466337ee' class='rChart nvd3Plot dimple'></div>
<br/>
<pre><code class='r'>require(rCharts)
require(reshape2)
licenses <- data.frame(
c("Dimple","Highcharts","Leaflet","Morris","NVD3","Polycharts","Rickshaw","xCharts"),
c("MIT","CCA Noncommercial 3.0","MIT","MIT","Apache Ver 2","CCA Noncommercial 3.0","MIT","MIT"),
c("MIT","Paid","MIT","MIT","Apache Ver 2","Paid","MIT","MIT")
)
colnames(licenses) <- c("Library","Noncommercial","Commercial")
licenses.melt <- melt(licenses, id.var = 1)
colnames(licenses.melt) <- c("Library", "Type", "License")
licPlot <- dPlot(
x = c("License","Type"),
y = "Library",
groups = "Type",
data = licenses.melt,
type = "bar"
)
licPlot$xAxis ( type = "addCategoryAxis" )
licPlot$yAxis ( type = "addCategoryAxis" )
licPlot$legend(
x = 200,
y = 10,
width = 400,
height = 20,
horizontalAlign = "right"
)
licPlot
</code></pre>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var opts = {
"dom": "chart1aa466337ee",
"width": 800,
"height": 400,
"x": [ "License", "Type" ],
"y": "Library",
"groups": "Type",
"type": "bar",
"id": "chart1aa466337ee"
},
data = [
{
"Library": "Dimple",
"Type": "Noncommercial",
"License": "MIT"
},
{
"Library": "Highcharts",
"Type": "Noncommercial",
"License": "CCA Noncommercial 3.0"
},
{
"Library": "Leaflet",
"Type": "Noncommercial",
"License": "MIT"
},
{
"Library": "Morris",
"Type": "Noncommercial",
"License": "MIT"
},
{
"Library": "NVD3",
"Type": "Noncommercial",
"License": "Apache Ver 2"
},
{
"Library": "Polycharts",
"Type": "Noncommercial",
"License": "CCA Noncommercial 3.0"
},
{
"Library": "Rickshaw",
"Type": "Noncommercial",
"License": "MIT"
},
{
"Library": "xCharts",
"Type": "Noncommercial",
"License": "MIT"
},
{
"Library": "Dimple",
"Type": "Commercial",
"License": "MIT"
},
{
"Library": "Highcharts",
"Type": "Commercial",
"License": "Paid"
},
{
"Library": "Leaflet",
"Type": "Commercial",
"License": "MIT"
},
{
"Library": "Morris",
"Type": "Commercial",
"License": "MIT"
},
{
"Library": "NVD3",
"Type": "Commercial",
"License": "Apache Ver 2"
},
{
"Library": "Polycharts",
"Type": "Commercial",
"License": "Paid"
},
{
"Library": "Rickshaw",
"Type": "Commercial",
"License": "MIT"
},
{
"Library": "xCharts",
"Type": "Commercial",
"License": "MIT"
}
],
xAxis = {
"type": "addCategoryAxis",
"showPercent": false
},
yAxis = {
"type": "addCategoryAxis",
"showPercent": false
},
zAxis = [],
colorAxis = [],
legend = {
"x": 200,
"y": 10,
"width": 400,
"height": 20,
"horizontalAlign": "right"
};
var svg = dimple.newSvg("#" + opts.id, opts.width, opts.height);
var myChart = new dimple.chart(svg, data);
if (opts.bounds) {
myChart.setBounds(opts.bounds.x, opts.bounds.y, opts.bounds.width, opts.bounds.height);
}
if(opts.noFormats) { myChart.noFormats = opts.noFormats; };
var x;
if(xAxis.measure) {
x = myChart[xAxis.type]("x",opts.x,xAxis.measure);
} else {
x = myChart[xAxis.type]("x", opts.x);
};
if(!(xAxis.type === "addPctAxis")) x.showPercent = xAxis.showPercent;
if (xAxis.orderRule) x.addOrderRule(xAxis.orderRule);
if (xAxis.grouporderRule) x.addGroupOrderRule(xAxis.grouporderRule);
if (xAxis.overrideMin) x.overrideMin = xAxis.overrideMin;
if (xAxis.overrideMax) x.overrideMax = xAxis.overrideMax;
if (xAxis.overrideMax) x.overrideMax = xAxis.overrideMax;
if (xAxis.inputFormat) x.dateParseFormat = xAxis.inputFormat;
if (xAxis.outputFormat) x.tickFormat = xAxis.outputFormat;
var y;
if(yAxis.measure) {
y = myChart[yAxis.type]("y",opts.y,yAxis.measure);
} else {
y = myChart[yAxis.type]("y", opts.y);
};
if(!(yAxis.type === "addPctAxis")) y.showPercent = yAxis.showPercent;
if (yAxis.orderRule) y.addOrderRule(yAxis.orderRule);
if (yAxis.grouporderRule) y.addGroupOrderRule(yAxis.grouporderRule);
if (yAxis.overrideMin) y.overrideMin = yAxis.overrideMin;
if (yAxis.overrideMax) y.overrideMax = yAxis.overrideMax;
if (yAxis.inputFormat) y.dateParseFormat = yAxis.inputFormat;
if (yAxis.outputFormat) y.tickFormat = yAxis.outputFormat;
var z;
if (!(typeof(zAxis) === 'undefined') && zAxis.type){
if(zAxis.measure) {
z = myChart[zAxis.type]("z",opts.z,zAxis.measure);
} else {
z = myChart[zAxis.type]("z", opts.z);
};
if(!(zAxis.type === "addPctAxis")) z.showPercent = zAxis.showPercent;
if (zAxis.orderRule) z.addOrderRule(zAxis.orderRule);
if (zAxis.overrideMin) z.overrideMin = zAxis.overrideMin;
if (zAxis.overrideMax) z.overrideMax = zAxis.overrideMax;
}
if(d3.keys(colorAxis).length > 0) {
myChart[colorAxis.type](colorAxis.colorSeries,colorAxis.palette) ;
}
if(opts.hasOwnProperty("groups")) {
var s = myChart.addSeries( opts.groups, dimple.plot[opts.type] );
if (!(typeof(opts.aggregate) === 'undefined')) {
s.aggregate = eval(opts.aggregate);
}
if (!(typeof(opts.lineWeight) === 'undefined')) {
s.lineWeight = eval(opts.lineWeight);
}
if (!(typeof(opts.barGap) === 'undefined')) {
s.barGap = eval(opts.barGap);
}
} else var s = myChart.addSeries( null, dimple.plot[opts.type] );
if(d3.keys(legend).length > 0) {
var l =myChart.addLegend();
d3.keys(legend).forEach(function(d){
l[d] = legend[d];
});
}
if(opts.storyboard) {
myChart.setStoryboard(opts.storyboard);
};
myChart.draw();
</script>
</body>
<script src="//cdnjs.cloudflare.com/ajax/libs/prettify/188.0.0/prettify.js"></script>
<script
src='https://google-code-prettify.googlecode.com/svn-history/r232/trunk/src/lang-r.js'>
</script>
<script>
var pres = document.getElementsByTagName("pre");
for (var i=0; i < pres.length; ++i) {
pres[i].className = "prettyprint linenums";
}
prettyPrint();
</script>
</html>
code.R
require(rCharts)
require(reshape2)
licenses <- data.frame(
c("Dimple","Highcharts","Leaflet","Morris","NVD3","Polycharts","Rickshaw","xCharts"),
c("MIT","CCA Noncommercial 3.0","MIT","MIT","Apache Ver 2","CCA Noncommercial 3.0","MIT","MIT"),
c("MIT","Paid","MIT","MIT","Apache Ver 2","Paid","MIT","MIT")
)
colnames(licenses) <- c("Library","Noncommercial","Commercial")
licenses.melt <- melt(licenses, id.var = 1)
colnames(licenses.melt) <- c("Library", "Type", "License")
licPlot <- dPlot(
x = c("License","Type"),
y = "Library",
groups = "Type",
data = licenses.melt,
type = "bar"
)
licPlot$xAxis ( type = "addCategoryAxis" )
licPlot$yAxis ( type = "addCategoryAxis" )
licPlot$legend(
x = 200,
y = 10,
width = 400,
height = 20,
horizontalAlign = "right"
)
licPlot