Skip to content

Instantly share code, notes, and snippets.

@reinholdsson
Created July 20, 2013 16:19
Show Gist options
  • Save reinholdsson/6045600 to your computer and use it in GitHub Desktop.
Save reinholdsson/6045600 to your computer and use it in GitHub Desktop.
cData <- read.table(textConnection("
no Grade Count
1 01 40272
2 02 36902
3 03 1288
4 04 992
5 05 517
6 K 334
7 KA 8236
8 KP 6704"), sep = '', header = T
)
# -1 since categories starts from 0
data <- data.frame(
x = as.integer(cData$Grade)-1,
y = as.integer(cData$Grade)-1
)
a <- rCharts:::Highcharts$new()
a$series(data = toJSONArray2(data, json = F, names = F))
a$chart(type = "bar")
a$xAxis(categories = as.character(cData$Grade))
a$yAxis(categories = as.character(cData$Grade))
a
<!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://twitter.github.io/bootstrap/assets/js/google-code-prettify/prettify.css">
<link rel='stylesheet' href="http://aozora.github.io/bootplus/assets/css/docs.css">
<script src='http://code.jquery.com/jquery-1.9.1.min.js' type='text/javascript'></script>
<script src='http://code.highcharts.com/highcharts.js' type='text/javascript'></script>
<script src='http://code.highcharts.com/highcharts-more.js' type='text/javascript'></script>
<style>
.rChart {
display: block
margin: auto auto;
width: 100%;
height: 400px;
}
/*
body {
margin-top: 60px;
}
*/
</style>
</head>
<body>
<div class='container'>
<div class='row'>
<div class='span8'>
<div class="bs-docs-example">
<div id='chart12b046b76727' class='rChart nvd3Plot highcharts'></div>
<br/>
<pre><code class='r'>cData &lt;- read.table(textConnection(&quot;
no Grade Count
1 01 40272
2 02 36902
3 03 1288
4 04 992
5 05 517
6 K 334
7 KA 8236
8 KP 6704&quot;), sep = '', header = T
)
# -1 since categories starts from 0
data &lt;- data.frame(
x = as.integer(cData$Grade)-1,
y = as.integer(cData$Grade)-1
)
a &lt;- rCharts:::Highcharts$new()
a$series(data = toJSONArray2(data, json = F, names = F))
a$chart(type = &quot;bar&quot;)
a$xAxis(categories = as.character(cData$Grade))
a$yAxis(categories = as.character(cData$Grade))
a
</code></pre>
</div>
</div>
</div>
</div>
<script type='text/javascript'>
(function($){
$(function () {
var chart = new Highcharts.Chart({
"dom": "chart12b046b76727",
"width": 800,
"height": 400,
"credits": {
"href": null,
"text": null
},
"title": {
"text": null
},
"yAxis": {
"categories": [ "01", "02", "03", "04", "05", "K", "KA", "KP" ]
},
"series": [
{
"data": [
[
0,
0
],
[
1,
1
],
[
2,
2
],
[
3,
3
],
[
4,
4
],
[
5,
5
],
[
6,
6
],
[
7,
7
]
]
}
],
"chart": {
"type": "bar",
"renderTo": "chart12b046b76727"
},
"xAxis": {
"categories": [ "01", "02", "03", "04", "05", "K", "KA", "KP" ]
},
"id": "chart12b046b76727"
});
});
})(jQuery);
</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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment