Created
March 9, 2014 21:56
-
-
Save heathermkrause/9455359 to your computer and use it in GitHub Desktop.
PL Countplot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype HTML> | |
<meta charset = 'utf-8'> | |
<html> | |
<head> | |
<link rel='stylesheet' href='http://nvd3.org/src/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/lib/fisheye.js' type='text/javascript'></script> | |
<style> | |
.rChart { | |
display: block; | |
margin-left: auto; | |
margin-right: auto; | |
width: 800px; | |
height: 400px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id='chart9c53676e802' class='rChart nvd3'></div> | |
<script type='text/javascript'> | |
$(document).ready(function(){ | |
drawchart9c53676e802() | |
}); | |
function drawchart9c53676e802(){ | |
var opts = { | |
"dom": "chart9c53676e802", | |
"width": 800, | |
"height": 400, | |
"x": "Country", | |
"y": "PLCount", | |
"group": "Grade", | |
"type": "multiBarChart", | |
"title": "Grade Proportions by County", | |
"id": "chart9c53676e802" | |
}, | |
data = [ | |
{ | |
"Country": "Malawi Groundnut", | |
"Grade": "A", | |
"SWCount": 21, | |
"UICount": 86, | |
"PLCount": 0, | |
"PDCount": 25, | |
"SPCount": 0, | |
"HVCount": 165, | |
"PHCount": 9, | |
"MKCount": 16, | |
"RKCount": 9, | |
"GDCount": 85, | |
"SWPercent": 0.12, | |
"UIPercent": 0.5, | |
"PLPercent": 0, | |
"PDPercent": 0.15, | |
"SPPercent": 0, | |
"HVPercent": 0.96, | |
"PHPercent": 0.05, | |
"MKPercent": 0.09, | |
"RKPercent": 0.05, | |
"GDPercent": 0.5 | |
}, | |
{ | |
"Country": "Malawi Groundnut", | |
"Grade": "B", | |
"SWCount": 75, | |
"UICount": 38, | |
"PLCount": 0, | |
"PDCount": 99, | |
"SPCount": 0, | |
"HVCount": 2, | |
"PHCount": 136, | |
"MKCount": 23, | |
"RKCount": 12, | |
"GDCount": 69, | |
"SWPercent": 0.44, | |
"UIPercent": 0.22, | |
"PLPercent": 0, | |
"PDPercent": 0.58, | |
"SPPercent": 0, | |
"HVPercent": 0.01, | |
"PHPercent": 0.8, | |
"MKPercent": 0.13, | |
"RKPercent": 0.07, | |
"GDPercent": 0.4 | |
}, | |
{ | |
"Country": "Malawi Groundnut", | |
"Grade": "C", | |
"SWCount": 47, | |
"UICount": 42, | |
"PLCount": 138, | |
"PDCount": 44, | |
"SPCount": 0, | |
"HVCount": 2, | |
"PHCount": 19, | |
"MKCount": 92, | |
"RKCount": 24, | |
"GDCount": 14, | |
"SWPercent": 0.27, | |
"UIPercent": 0.25, | |
"PLPercent": 0.81, | |
"PDPercent": 0.26, | |
"SPPercent": 0, | |
"HVPercent": 0.01, | |
"PHPercent": 0.11, | |
"MKPercent": 0.54, | |
"RKPercent": 0.14, | |
"GDPercent": 0.08 | |
}, | |
{ | |
"Country": "Malawi Groundnut", | |
"Grade": "D", | |
"SWCount": 28, | |
"UICount": 0, | |
"PLCount": 33, | |
"PDCount": 3, | |
"SPCount": 171, | |
"HVCount": 2, | |
"PHCount": 7, | |
"MKCount": 40, | |
"RKCount": 126, | |
"GDCount": 3, | |
"SWPercent": 0.16, | |
"UIPercent": 0, | |
"PLPercent": 0.19, | |
"PDPercent": 0.02, | |
"SPPercent": 1, | |
"HVPercent": 0.01, | |
"PHPercent": 0.04, | |
"MKPercent": 0.23, | |
"RKPercent": 0.74, | |
"GDPercent": 0.02 | |
}, | |
{ | |
"Country": "Malawi Soy", | |
"Grade": "A", | |
"SWCount": 14, | |
"UICount": 82, | |
"PLCount": 0, | |
"PDCount": 12, | |
"SPCount": 0, | |
"HVCount": 2, | |
"PHCount": 1, | |
"MKCount": 24, | |
"RKCount": 4, | |
"GDCount": 66, | |
"SWPercent": 0.09, | |
"UIPercent": 0.54, | |
"PLPercent": 0, | |
"PDPercent": 0.08, | |
"SPPercent": 0, | |
"HVPercent": 0.01, | |
"PHPercent": 0.01, | |
"MKPercent": 0.16, | |
"RKPercent": 0.03, | |
"GDPercent": 0.44 | |
}, | |
{ | |
"Country": "Malawi Soy", | |
"Grade": "B", | |
"SWCount": 48, | |
"UICount": 37, | |
"PLCount": 0, | |
"PDCount": 83, | |
"SPCount": 0, | |
"HVCount": 2, | |
"PHCount": 136, | |
"MKCount": 26, | |
"RKCount": 12, | |
"GDCount": 69, | |
"SWPercent": 0.32, | |
"UIPercent": 0.25, | |
"PLPercent": 0, | |
"PDPercent": 0.55, | |
"SPPercent": 0, | |
"HVPercent": 0.01, | |
"PHPercent": 0.9, | |
"MKPercent": 0.17, | |
"RKPercent": 0.08, | |
"GDPercent": 0.46 | |
}, | |
{ | |
"Country": "Malawi Soy", | |
"Grade": "C", | |
"SWCount": 58, | |
"UICount": 20, | |
"PLCount": 118, | |
"PDCount": 50, | |
"SPCount": 0, | |
"HVCount": 146, | |
"PHCount": 12, | |
"MKCount": 74, | |
"RKCount": 20, | |
"GDCount": 12, | |
"SWPercent": 0.38, | |
"UIPercent": 0.13, | |
"PLPercent": 0.78, | |
"PDPercent": 0.33, | |
"SPPercent": 0, | |
"HVPercent": 0.97, | |
"PHPercent": 0.08, | |
"MKPercent": 0.49, | |
"RKPercent": 0.13, | |
"GDPercent": 0.08 | |
}, | |
{ | |
"Country": "Malawi Soy", | |
"Grade": "D", | |
"SWCount": 31, | |
"UICount": 12, | |
"PLCount": 33, | |
"PDCount": 6, | |
"SPCount": 151, | |
"HVCount": 0, | |
"PHCount": 2, | |
"MKCount": 27, | |
"RKCount": 115, | |
"GDCount": 4, | |
"SWPercent": 0.21, | |
"UIPercent": 0.08, | |
"PLPercent": 0.22, | |
"PDPercent": 0.04, | |
"SPPercent": 1, | |
"HVPercent": 0, | |
"PHPercent": 0.01, | |
"MKPercent": 0.18, | |
"RKPercent": 0.76, | |
"GDPercent": 0.03 | |
}, | |
{ | |
"Country": "Ghana Soy", | |
"Grade": "A", | |
"SWCount": 19, | |
"UICount": 43, | |
"PLCount": 22, | |
"PDCount": 8, | |
"SPCount": 17, | |
"HVCount": 26, | |
"PHCount": 14, | |
"MKCount": 30, | |
"RKCount": 21, | |
"GDCount": 28, | |
"SWPercent": 0.44, | |
"UIPercent": 1, | |
"PLPercent": 0.51, | |
"PDPercent": 0.19, | |
"SPPercent": 0.4, | |
"HVPercent": 0.6, | |
"PHPercent": 0.33, | |
"MKPercent": 0.7, | |
"RKPercent": 0.49, | |
"GDPercent": 0.65 | |
}, | |
{ | |
"Country": "Ghana Soy", | |
"Grade": "B", | |
"SWCount": 20, | |
"UICount": 0, | |
"PLCount": 12, | |
"PDCount": 18, | |
"SPCount": 4, | |
"HVCount": 1, | |
"PHCount": 14, | |
"MKCount": 5, | |
"RKCount": 17, | |
"GDCount": 13, | |
"SWPercent": 0.47, | |
"UIPercent": 0, | |
"PLPercent": 0.28, | |
"PDPercent": 0.42, | |
"SPPercent": 0.09, | |
"HVPercent": 0.02, | |
"PHPercent": 0.33, | |
"MKPercent": 0.12, | |
"RKPercent": 0.4, | |
"GDPercent": 0.3 | |
}, | |
{ | |
"Country": "Ghana Soy", | |
"Grade": "C", | |
"SWCount": 4, | |
"UICount": 0, | |
"PLCount": 8, | |
"PDCount": 15, | |
"SPCount": 15, | |
"HVCount": 3, | |
"PHCount": 10, | |
"MKCount": 7, | |
"RKCount": 3, | |
"GDCount": 2, | |
"SWPercent": 0.09, | |
"UIPercent": 0, | |
"PLPercent": 0.19, | |
"PDPercent": 0.35, | |
"SPPercent": 0.35, | |
"HVPercent": 0.07, | |
"PHPercent": 0.23, | |
"MKPercent": 0.16, | |
"RKPercent": 0.07, | |
"GDPercent": 0.05 | |
}, | |
{ | |
"Country": "Ghana Soy", | |
"Grade": "D", | |
"SWCount": 0, | |
"UICount": 0, | |
"PLCount": 1, | |
"PDCount": 2, | |
"SPCount": 7, | |
"HVCount": 13, | |
"PHCount": 5, | |
"MKCount": 1, | |
"RKCount": 2, | |
"GDCount": 0, | |
"SWPercent": 0, | |
"UIPercent": 0, | |
"PLPercent": 0.02, | |
"PDPercent": 0.05, | |
"SPPercent": 0.16, | |
"HVPercent": 0.3, | |
"PHPercent": 0.12, | |
"MKPercent": 0.02, | |
"RKPercent": 0.05, | |
"GDPercent": 0 | |
}, | |
{ | |
"Country": "Bangladesh Indigo", | |
"Grade": "A", | |
"SWCount": 1, | |
"UICount": 6, | |
"PLCount": 10, | |
"PDCount": 4, | |
"SPCount": 4, | |
"HVCount": 6, | |
"PHCount": 12, | |
"MKCount": 7, | |
"RKCount": 4, | |
"GDCount": 6, | |
"SWPercent": 0.05, | |
"UIPercent": 0.27, | |
"PLPercent": 0.45, | |
"PDPercent": 0.18, | |
"SPPercent": 0.18, | |
"HVPercent": 0.27, | |
"PHPercent": 0.55, | |
"MKPercent": 0.32, | |
"RKPercent": 0.18, | |
"GDPercent": 0.27 | |
}, | |
{ | |
"Country": "Bangladesh Indigo", | |
"Grade": "B", | |
"SWCount": 9, | |
"UICount": 8, | |
"PLCount": 5, | |
"PDCount": 7, | |
"SPCount": 2, | |
"HVCount": 6, | |
"PHCount": 3, | |
"MKCount": 4, | |
"RKCount": 3, | |
"GDCount": 7, | |
"SWPercent": 0.41, | |
"UIPercent": 0.36, | |
"PLPercent": 0.23, | |
"PDPercent": 0.32, | |
"SPPercent": 0.09, | |
"HVPercent": 0.27, | |
"PHPercent": 0.14, | |
"MKPercent": 0.18, | |
"RKPercent": 0.14, | |
"GDPercent": 0.32 | |
}, | |
{ | |
"Country": "Bangladesh Indigo", | |
"Grade": "C", | |
"SWCount": 5, | |
"UICount": 3, | |
"PLCount": 3, | |
"PDCount": 5, | |
"SPCount": 9, | |
"HVCount": 3, | |
"PHCount": 2, | |
"MKCount": 5, | |
"RKCount": 3, | |
"GDCount": 3, | |
"SWPercent": 0.23, | |
"UIPercent": 0.14, | |
"PLPercent": 0.14, | |
"PDPercent": 0.23, | |
"SPPercent": 0.41, | |
"HVPercent": 0.14, | |
"PHPercent": 0.09, | |
"MKPercent": 0.23, | |
"RKPercent": 0.14, | |
"GDPercent": 0.14 | |
}, | |
{ | |
"Country": "Bangladesh Indigo", | |
"Grade": "D", | |
"SWCount": 7, | |
"UICount": 5, | |
"PLCount": 4, | |
"PDCount": 6, | |
"SPCount": 7, | |
"HVCount": 7, | |
"PHCount": 5, | |
"MKCount": 6, | |
"RKCount": 12, | |
"GDCount": 6, | |
"SWPercent": 0.32, | |
"UIPercent": 0.23, | |
"PLPercent": 0.18, | |
"PDPercent": 0.27, | |
"SPPercent": 0.32, | |
"HVPercent": 0.32, | |
"PHPercent": 0.23, | |
"MKPercent": 0.27, | |
"RKPercent": 0.55, | |
"GDPercent": 0.27 | |
} | |
] | |
if(!(opts.type==="pieChart" || opts.type==="sparklinePlus")) { | |
var data = d3.nest() | |
.key(function(d){ | |
//return opts.group === undefined ? 'main' : d[opts.group] | |
//instead of main would think a better default is opts.x | |
return opts.group === undefined ? opts.y : d[opts.group]; | |
}) | |
.entries(data); | |
} | |
if (opts.disabled != undefined){ | |
data.map(function(d, i){ | |
d.disabled = opts.disabled[i] | |
}) | |
} | |
nv.addGraph(function() { | |
var chart = nv.models[opts.type]() | |
.x(function(d) { return d[opts.x] }) | |
.y(function(d) { return d[opts.y] }) | |
.width(opts.width) | |
.height(opts.height) | |
chart | |
.color([ "#a1dab4", "#41b6c4", "#2c7fb8", "#253494" ]) | |
chart.xAxis | |
.axisLabel("Count of Groups by Grade in the Planting Domain (A is the high score, D is the low score)") | |
chart.yAxis | |
.axisLabel("Percent of Total Groups") | |
d3.select("#" + opts.id) | |
.append('svg') | |
.datum(data) | |
.transition().duration(500) | |
.call(chart); | |
nv.utils.windowResize(chart.update); | |
return chart; | |
}); | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment