Skip to content

Instantly share code, notes, and snippets.

@AnotherContext
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnotherContext/a61feff018318c64af2a to your computer and use it in GitHub Desktop.
Save AnotherContext/a61feff018318c64af2a to your computer and use it in GitHub Desktop.
Domestic abuse: regions by assistance calls comparison
#continuation of DA_CallsVsRegion.R
p1.2a <- nPlot(value ~ variable, group = 'Region.Name',
data = da1_data,
type = 'multiBarChart'
)
p1.2a$set(dom = 'chart2', width = 1000)
p1.2a
#p1.2a$publish('Domestic abuse: regions by assistance calls comparison',host='gist')
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href='http://nvd3.org/assets/css/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/assets/lib/fisheye.js' type='text/javascript'></script>
<style>
.rChart {
display: block;
margin-left: auto;
margin-right: auto;
width: 1000px;
height: 400px;
}
</style>
</head>
<body >
<div id = 'chart2' class = 'rChart nvd3'></div>
<script type='text/javascript'>
$(document).ready(function(){
drawchart2()
});
function drawchart2(){
var opts = {
"dom": "chart2",
"width": 1000,
"height": 400,
"x": "variable",
"y": "value",
"group": "Region.Name",
"type": "multiBarChart",
"id": "chart2"
},
data = [
{
"Area.Name": 107,
"Region.Name": "East Midlands Region",
"variable": "Number.of.calls.for.assistance",
"value": 1841510
},
{
"Area.Name": 99,
"Region.Name": "East of England Region",
"variable": "Number.of.calls.for.assistance",
"value": 1980273
},
{
"Area.Name": 51,
"Region.Name": "London Region",
"variable": "Number.of.calls.for.assistance",
"value": 5283157
},
{
"Area.Name": 48,
"Region.Name": "North East Region",
"variable": "Number.of.calls.for.assistance",
"value": 851526
},
{
"Area.Name": 71,
"Region.Name": "North West Region",
"variable": "Number.of.calls.for.assistance",
"value": 2744545
},
{
"Area.Name": 151,
"Region.Name": "South East Region",
"variable": "Number.of.calls.for.assistance",
"value": 2414414
},
{
"Area.Name": 39,
"Region.Name": "South West Region",
"variable": "Number.of.calls.for.assistance",
"value": 2141191
},
{
"Area.Name": 89,
"Region.Name": "Wales",
"variable": "Number.of.calls.for.assistance",
"value": 1059248
},
{
"Area.Name": 158,
"Region.Name": "West Midlands Region",
"variable": "Number.of.calls.for.assistance",
"value": 1819397
},
{
"Area.Name": 133,
"Region.Name": "Yorkshire and the Humber Region",
"variable": "Number.of.calls.for.assistance",
"value": 1049847
},
{
"Area.Name": 107,
"Region.Name": "East Midlands Region",
"variable": "Total.crime",
"value": 246707
},
{
"Area.Name": 99,
"Region.Name": "East of England Region",
"variable": "Total.crime",
"value": 313845
},
{
"Area.Name": 51,
"Region.Name": "London Region",
"variable": "Total.crime",
"value": 749813
},
{
"Area.Name": 48,
"Region.Name": "North East Region",
"variable": "Total.crime",
"value": 138189
},
{
"Area.Name": 71,
"Region.Name": "North West Region",
"variable": "Total.crime",
"value": 439074
},
{
"Area.Name": 151,
"Region.Name": "South East Region",
"variable": "Total.crime",
"value": 452106
},
{
"Area.Name": 39,
"Region.Name": "South West Region",
"variable": "Total.crime",
"value": 255292
},
{
"Area.Name": 89,
"Region.Name": "Wales",
"variable": "Total.crime",
"value": 179160
},
{
"Area.Name": 158,
"Region.Name": "West Midlands Region",
"variable": "Total.crime",
"value": 426149
},
{
"Area.Name": 133,
"Region.Name": "Yorkshire and the Humber Region",
"variable": "Total.crime",
"value": 249484
},
{
"Area.Name": 107,
"Region.Name": "East Midlands Region",
"variable": "calls.for.assistance.with.DA.marker",
"value": 79584
},
{
"Area.Name": 99,
"Region.Name": "East of England Region",
"variable": "calls.for.assistance.with.DA.marker",
"value": 82199
},
{
"Area.Name": 51,
"Region.Name": "London Region",
"variable": "calls.for.assistance.with.DA.marker",
"value": 226616
},
{
"Area.Name": 48,
"Region.Name": "North East Region",
"variable": "calls.for.assistance.with.DA.marker",
"value": 58012
},
{
"Area.Name": 71,
"Region.Name": "North West Region",
"variable": "calls.for.assistance.with.DA.marker",
"value": 143257
},
{
"Area.Name": 151,
"Region.Name": "South East Region",
"variable": "calls.for.assistance.with.DA.marker",
"value": 120282
},
{
"Area.Name": 39,
"Region.Name": "South West Region",
"variable": "calls.for.assistance.with.DA.marker",
"value": 60282
},
{
"Area.Name": 89,
"Region.Name": "Wales",
"variable": "calls.for.assistance.with.DA.marker",
"value": 46771
},
{
"Area.Name": 158,
"Region.Name": "West Midlands Region",
"variable": "calls.for.assistance.with.DA.marker",
"value": 123123
},
{
"Area.Name": 133,
"Region.Name": "Yorkshire and the Humber Region",
"variable": "calls.for.assistance.with.DA.marker",
"value": 70351
},
{
"Area.Name": 107,
"Region.Name": "East Midlands Region",
"variable": "crime.with.a.DA.marker",
"value": 19396
},
{
"Area.Name": 99,
"Region.Name": "East of England Region",
"variable": "crime.with.a.DA.marker",
"value": 26655
},
{
"Area.Name": 51,
"Region.Name": "London Region",
"variable": "crime.with.a.DA.marker",
"value": 53540
},
{
"Area.Name": 48,
"Region.Name": "North East Region",
"variable": "crime.with.a.DA.marker",
"value": 12604
},
{
"Area.Name": 71,
"Region.Name": "North West Region",
"variable": "crime.with.a.DA.marker",
"value": 34144
},
{
"Area.Name": 151,
"Region.Name": "South East Region",
"variable": "crime.with.a.DA.marker",
"value": 35105
},
{
"Area.Name": 39,
"Region.Name": "South West Region",
"variable": "crime.with.a.DA.marker",
"value": 21712
},
{
"Area.Name": 89,
"Region.Name": "Wales",
"variable": "crime.with.a.DA.marker",
"value": 13100
},
{
"Area.Name": 158,
"Region.Name": "West Midlands Region",
"variable": "crime.with.a.DA.marker",
"value": 32125
},
{
"Area.Name": 133,
"Region.Name": "Yorkshire and the Humber Region",
"variable": "crime.with.a.DA.marker",
"value": 21317
}
]
if(!(opts.type==="pieChart" || opts.type==="sparklinePlus" || opts.type==="bulletChart")) {
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]()
.width(opts.width)
.height(opts.height)
if (opts.type != "bulletChart"){
chart
.x(function(d) { return d[opts.x] })
.y(function(d) { return d[opts.y] })
}
d3.select("#" + opts.id)
.append('svg')
.datum(data)
.transition().duration(500)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
};
</script>
<script></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment