Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Last active January 20, 2016 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ramnathv/6847603 to your computer and use it in GitHub Desktop.
Save ramnathv/6847603 to your computer and use it in GitHub Desktop.
Waterfall Chart with rCharts and uvCharts
# install_github('rCharts', 'ramnathv', ref = 'dev')
require(rCharts)
dat <- read.csv(textConnection('x, y
"2005 Actual", 90
"Price", 15
"Volume", 21
"Fixes", -37
"Taxation", -43
"Escalation", -40
"Mix", 46
"Market Effect", 91
"Partners", 61')
)
uPlot("x", "y", data = dat, type = 'Waterfall')
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href="http://netdna.bootstrapcdn.com/bootswatch/2.3.1/cosmo/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css" >
<link rel='stylesheet' href="http://getbootstrap.com/2.3.2/assets/js/google-code-prettify/prettify.css">
<link rel='stylesheet' href="http://aozora.github.io/bootplus/assets/css/docs.css">
<script src='http://cdnjs.cloudflare.com/ajax/libs/d3/3.2.2/d3.v3.min.js' type='text/javascript'></script>
<script src='http://imaginea.github.io/uvCharts/js/uvcharts.js' type='text/javascript'></script>
<style>
.rChart {
display: block
margin: auto auto;
width: 100%;
height: 100%;
}
/*
body {
margin-top: 60px;
}
*/
</style>
</head>
<body>
<div class='container'>
<div class='row'>
<div class='span8'>
<div class="bs-docs-example">
<div id='chartdf5a59da4e54' class='rChart uvcharts'>
</div>
<br/>
<pre><code class='r'># install_github('rCharts', 'ramnathv', ref = 'dev')
require(rCharts)
dat &lt;- read.csv(textConnection('x, y
&quot;2005 Actual&quot;, 90
&quot;Price&quot;, 15
&quot;Volume&quot;, 21
&quot;Fixes&quot;, -37
&quot;Taxation&quot;, -43
&quot;Escalation&quot;, -40
&quot;Mix&quot;, 46
&quot;Market Effect&quot;, 91
&quot;Partners&quot;, 61')
)
uPlot(&quot;x&quot;, &quot;y&quot;, data = dat, type = 'Waterfall')
</code></pre>
</div>
</div>
</div>
</div>
<script>
var chartParamschartdf5a59da4e54 = {
"dom": "chartdf5a59da4e54",
"width": 700,
"height": 400,
"config": {
"meta": {
"position": "#uv-div"
}
},
"graphdef": {
"categories": [
"data"
],
"dataset": {
"data": [
{
"name": " 2005 Actual",
"value": 90
},
{
"name": " Price",
"value": 15
},
{
"name": " Volume",
"value": 21
},
{
"name": " Fixes",
"value": -37
},
{
"name": " Taxation",
"value": -43
},
{
"name": " Escalation",
"value": -40
},
{
"name": " Mix",
"value": 46
},
{
"name": " Market Effect",
"value": 91
},
{
"name": " Partners",
"value": 61
}
]
}
},
"type": "Waterfall",
"id": "chartdf5a59da4e54"
}
var graphdefchartdf5a59da4e54 = chartParamschartdf5a59da4e54.graphdef
var configchartdf5a59da4e54 = chartParamschartdf5a59da4e54.config
configchartdf5a59da4e54.meta.position = '#chartdf5a59da4e54'
var chartchartdf5a59da4e54 = uv.chart(chartParamschartdf5a59da4e54.type,
graphdefchartdf5a59da4e54,
configchartdf5a59da4e54
);
</script>
</body>
<!-- Google Prettify -->
<script src="http://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>
@tbenschop
Copy link

Thanks, this example is useful. I was wondering whether it is also possible to replicate the highcharts waterfall from http://www.highcharts.com/demo/waterfall since it looks so neat. I already tried it with highcharts in R but didn't find it so easy.. Very simplified code:
h1 <- Highcharts$new()
h1$series(name="y",data=2000,type='waterfall')
h1$series(name="y2",data=3000,type='waterfall')
h1$yAxis(title="USD")
h1$chart(type="waterfall", width = 400, height = 200)
h1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment