Skip to content

Instantly share code, notes, and snippets.

@phil-pedruco
Last active August 29, 2015 14:13
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 phil-pedruco/4e2084a8d749d268d20e to your computer and use it in GitHub Desktop.
Save phil-pedruco/4e2084a8d749d268d20e to your computer and use it in GitHub Desktop.

This map showning the rates of crises against women for 2015 is based on the data and analysis by Tinniam V Ganesh from this post. The darker areas have higher crime rates against women and the lighter are lower crime rates. The GIS data is from Diva GIS.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Crimes against Women in India</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" src="http://d3js.org/topojson.v1.min.js"></script>
</head>
<body>
<div id="map"></div>
</body>
<script type="text/javascript">
var h = 500,
w = 960;
// set-up unit projection and path
var projection = d3.geo.mercator()
.scale(1)
.translate([0, 0]);
var path = d3.geo.path()
.projection(projection);
// set-up svg canvas
var svg = d3.select("body").append("svg")
.attr("height", h)
.attr("width", w);
// set-up scale for colour coding crime
var cScale = d3.scale.linear()
.domain([0, 1]);
// read in topojson of India
d3.json("data/india.json", function(error, india) {
// crime statistics from https://gigadom.wordpress.com/2015/01/16/a-crime-map-of-india-in-r-crime-against-women/
d3.csv("data/Total_crimes_against_women.csv", function(error, crimes) {
var cRange = d3.extent(crimes, function(d, i) {
return +d["2015"]
});
cScale.domain(cRange);
var states = [];
crimes.forEach(function(d) {
var el = d.State
states.push(el)
});
var bTopo = topojson.feature(india, india.objects.india),
topo = bTopo.features;
topo.forEach(function(d, i) {
var n = states.indexOf(d.properties.NAME_1);
if (n !== -1) {
d.properties.crime = crimes[n]["2015"];
} else {
d.properties.crime = null;
}
});
// calculate bounds, scale and transform
// see http://stackoverflow.com/questions/14492284/center-a-map-in-d3-given-a-geojson-object
var b = path.bounds(bTopo),
s = .95 / Math.max((b[1][0] - b[0][0]) / w, (b[1][1] - b[0][1]) / h),
t = [(w - s * (b[1][0] + b[0][0])) / 2, (h - s * (b[1][1] + b[0][1])) / 2];
projection.scale(s)
.translate(t);
svg.selectAll("path")
.data(topo).enter()
.append("path")
.style("fill", function(d, i) {
if(d.properties.crime === null) {
return "grey";
} else {
return interp(cScale(+d.properties.crime));
}
})
.style("stroke", "black")
.attr("d", path);
});
});
function interp(x) {
var ans = d3.interpolateLab("#ffffe5", "#004529")(x);
return ans
}
</script>
</html>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Rank State 2013 2014 2015 2016 2017 2018
3 Andhra Pradesh 41971.47 43406.07 44840.67 46275.26 47709.86 49144.46
27 Arunachal Pradesh 189.08 190.22 191.36 192.5 193.64 194.78
8 Assam 17617.21 18176.91 18736.61 19296.31 19856.01 20415.71
12 Bihar 13143.79 13744.78 14345.77 14946.77 15547.76 16148.75
15 Chhattisgarh 6799.26 6942.73 7086.21 7229.68 7373.16 7516.64
20 Delhi 3728.21 3657.41 3586.61 3515.81 3445.01 3374.21
24 Goa 225.71 230.41 235.11 239.81 244.51 249.21
6 Gujarat 25225.33 26259.87 27294.41 28328.95 29363.49 30398.03
13 Haryana 7488.62 7583.23 7677.84 7772.45 7867.05 7961.66
22 Himachal Pradesh 1420.79 1436.9 1453 1469.11 1485.22 1501.33
17 Jammu and Kashmir 5004.2 5199.95 5395.69 5591.44 5787.19 5982.94
16 Jharkhand 5719.14 5915.81 6112.49 6309.16 6505.84 6702.51
9 Karnataka 16662.48 17341.5 18020.51 18699.52 19378.53 20057.54
11 Kerala 14300.59 14806.8 15313 15819.21 16325.42 16831.62
5 Madhya Pradesh 29155.17 29639.13 30123.09 30607.05 31091.01 31574.97
2 Maharashtra 43434.42 44636.9 45839.38 47041.85 48244.33 49446.8
26 Manipur 179.23 184.34 189.45 194.56 199.67 204.79
23 Meghalaya 276.48 295.92 315.35 334.79 354.22 373.65
25 Mizoram 189.39 195.2 201 206.81 212.61 218.41
29 Nagaland 74.55 77.78 81.02 84.26 87.5 90.73
7 Orissa 16496.3 17360.02 18223.73 19087.44 19951.16 20814.87
18 Punjab 4489 4524.73 4560.46 4596.19 4631.92 4667.65
10 Rajasthan 16719.21 17046.07 17372.92 17699.77 18026.62 18353.48
28 Sikkim 77.73 81.69 85.64 89.6 93.56 97.52
14 Tamil Nadu 9175.27 8846.01 8516.74 8187.48 7858.21 7528.94
19 Tripura 2692.64 2876.81 3060.99 3245.16 3429.34 3613.51
1 Uttar Pradesh 75662.09 79874.18 84086.27 88298.36 92510.45 96722.55
21 Uttaranchal 1721 1697.62 1674.23 1650.85 1627.46 1604.08
4 West Bengal 31828.74 33474.57 35120.41 36766.24 38412.07 40057.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment