Skip to content

Instantly share code, notes, and snippets.

@heathermkrause
Created April 14, 2015 01:40
Show Gist options
  • Save heathermkrause/5f97f1e3581148785a6c to your computer and use it in GitHub Desktop.
Save heathermkrause/5f97f1e3581148785a6c to your computer and use it in GitHub Desktop.
Domestic Violence Attitudes Scatterplot

This data is compiled from individual surveys conducted by the UN, UNICEF and USAID through several projects.

Each person was asked whether they felt domestic violence was acceptable.

The lack of attitude data from North American and European countries is problematic. I am working on a project to change this lack of data.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Scatterplot</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<style type="text/css">
body {
background-color: white;
font-family: Helvetica, Arial, sans-serif;
}
h1 {
font-size: 18px;
margin: 70;
}
p {
font-size: 12px;
margin: 12px 0 0 0;
stroke: red;
}
p2 {
font-size: 8px;
margin: 12px 0 0 0;
stroke: red;
}
svg {
background-color: white;
}
circle:hover {
fill: #8c96c6;
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 9px;
}
.xlabel{
font-family: sans-serif;
font-size: 9px;
}
.ylabel{
font-family: sans-serif;
font-size: 9px;
}
</style>
</head>
<body>
<h1>Attitudes towards Domestic Violence</h1>
<p>This data is compiled from individual surveys conducted by the UN, UNICEF and USAID through several projects.</p> <p>Each person was asked whether they felt domestic violence was acceptable.</p>
<p>It appears from the scatterplot on the left that in most countries more women than men say they find domestic violence acceptable.</p>
<p>It appears from the scatterplot on the right that more of the poorest women find domestic violence acceptable than the wealthiest women.</p>
<p>The lack of attitude data from North American and European countries is problematic. I am working on a project to change this lack of data.</p>
<p2>Sources: <a href="http://www.dhsprogram.com/">DHS</a>, 2000-2014 <a href="http://www.unicef.org/statistics/index_24302.html">MICS</a>, 2006-2014</p2>
<script type="text/javascript">
var w = 400;
var h = 400;
var padding = [ 20, 10, 50, 55 ]; //Top, right, bottom, left
var padding2 = [ 20, 10, 50, 55 ];
var xScale = d3.scale.linear()
.range([ padding[3], w - padding[1] - padding[3] ]);
var yScale2 = d3.scale.linear()
.range([ padding2[0], h - padding2[2] ]);
var xScale2 = d3.scale.linear()
.range([ padding2[3], w - padding2[1] - padding2[3] ]);
var yScale = d3.scale.linear()
.range([ padding[0], h - padding[2] ]);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.ticks(11)
.tickFormat(function(d) {
return d + "%";
});
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left")
.ticks(10)
.tickFormat(function(d) {
return d + "%";
});
var xAxis2 = d3.svg.axis()
.scale(xScale2)
.orient("bottom")
.ticks(10)
.tickFormat(function(d) {
return d + "%";
});
var yAxis2 = d3.svg.axis()
.scale(yScale2)
.orient("left")
.tickFormat(function(d) {
return d + "%";
});
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
d3.csv("VAWAttitudeUNICEFBoth Sexes2.csv", function(data) {
xScale.domain([
d3.min(data, function(d) {
return +d.MenTotal;
}),
100
]);
yScale.domain([
100,
d3.min(data, function(d) {
return +d.WomenTot;
})
]);
var circles = svg.selectAll("circle")
.data(data)
.enter()
.append("circle");
circles.attr("cx", function(d) {
if (d.MenTotal === "NA") {
return 50;
} else {
return xScale(d.MenTotal);
}
})
.attr("cy", function(d) {
return yScale(d.WomenTot);
})
.attr("r", 0,1)
.attr("fill", "#C91826")
.append("title")
.text(function(d) {
if(d.MenTotal === "NA") {
return "In " + d.Country + ", men's opinion is missing and " + d.WomenTot + "% of women accept domestic violence";
} else {
return "In " + d.Country + ", " + d.MenTotal + "% of men and " + d.WomenTot + "% of women accept domestic violence";
}
});
circles.sort(function(a, b) {
return d3.ascending(+a.WomenTot, +a.WomenTot);
})
.transition()
.delay(function(d, i) {
return i * 75;
})
.ease("circle")
.duration(2000)
.attr("r", 5);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + (h - padding[2] + 10) + ")")
.call(xAxis);
svg.append("text")
.attr("class", "xlabel")
.attr("text-anchor", "end")
.attr("x", w/2+ 115)
.attr("y", h - 6)
.text("Percent of Men who say domestic violence is acceptable");
svg.append("text")
.attr("class", "xlabel")
.attr("text-anchor", "end")
.attr("x", -370)
.attr("y", 50)
.attr("transform", function(d) {
return "rotate(-90)"
})
.text("Missing");
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + (padding[3] - 10) + ",0)")
.call(yAxis);
svg.append("text")
.attr("class", "ylabel")
.attr("text-anchor", "end")
.attr("y", 3)
.attr("x", -45)
.attr("dy", ".75em")
.attr("transform", "rotate(-90)")
.text("Percent of Women who say domestic violence is acceptable");
});
var svg2 = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h)
;
d3.csv("VAWAttitudeUNICEFBoth Sexes2.csv", function(data) {
xScale2.domain([
d3.min(data, function(d) {
return +d.WomPoorest;
}),
100
]);
yScale2.domain([
100,
d3.min(data, function(d) {
return +d.WomRichest;
})
]);
var circles = svg2.selectAll("circle")
.data(data)
.enter()
.append("circle");
circles.attr("cx", function(d) {
if (d.WomPoorest=== "NA") {
return 50;
} else {
return xScale2(d.WomPoorest);
}
})
.attr("cy", function(d) {
return yScale2(d.WomRichest);
})
.attr("r", 0.1)
.attr("fill", "#F2555C")
.append("title")
.text(function(d) {
if(d.WomPoorest === "NA") {
return "In " + d.Country + ", men's opinion is missing and " + d.WomRichest + "% of women accept domestic violence";
} else {
return "In " + d.Country + ", " + d.WomPoorest + "% of the poorest women and " + d.WomRichest + "% of the wealthiest women accept domestic violence";
}
});
circles.sort(function(a, b) {
return d3.ascending(+a.WomPoorest, +a.WomPoorest);
})
.transition()
.delay(function(d, i) {
return 7500+ i * 175;
})
.ease("circle")
.duration(2000)
.attr("r", 5);
svg2.append("g")
.attr("class", "x axis")
.transition()
.delay(7000)
.ease("linear")
.attr("transform", "translate(0," + (h - padding2[2] + 10) + ")")
.call(xAxis2)
;
svg2.append("text")
.transition()
.delay(7000)
.attr("class", "xlabel")
.attr("text-anchor", "end")
.attr("x", w/2 + 155)
.attr("y", h - 6)
.text("Percent of Country's Poorest Women who say domestic violence is acceptable");
svg2.append("g")
.attr("class", "y axis")
.transition()
.delay(7000)
.ease("linear")
.attr("transform", "translate(" + (padding2[3] - 10) + ",0)")
.call(yAxis2);
svg2.append("text")
.transition()
.delay(7000)
.attr("class", "ylabel")
.attr("text-anchor", "end")
.attr("y", 1)
.attr("x", -25)
.attr("dy", ".75em")
.attr("transform", "rotate(-90)")
.text("Percent of Country's Wealthiest Women who say domestic violence is acceptable");
});
</script>
</body>
</html>
Country Laws MenTotal MenUrban MenRural MenPoorest MenSecond MenMiddle MenFourth MenRichest MenYear WomenTot WomUrban WomRural WomPoorest WomSecond WomMiddle WomFourth WomRichest WomYear
Afghanistan NA NA NA NA NA NA NA NA NA NA 90 83 92 91 94 92 92 83 2010-2011
Albania Yes 36 27 45 52 45 37 32 21 2008-2009 30 18 39 49 38 30 22 10 2008-2009
Algeria No NA NA NA NA NA NA NA NA NA 68 63 75 80 75 69 65 53 2006
Argentina Yes NA NA NA NA NA NA NA NA NA 2 NA NA 4 3 2 1 1 2011-2012
Armenia No 20 15 28 32 21 22 15 10 2010 9 8 11 14 11 9 7 6 2010
Azerbaijan Yes 58 55 62 63 58 56 59 56 2006 49 40 61 66 63 52 39 30 2006
Bangladesh Yes NA NA NA NA NA NA NA NA NA 33 24 36 41 38 35 31 19 2011
Barbados NA NA NA NA NA NA NA NA NA NA 3 4 3 9 3 3 2 1 2012
Belarus NA 4 3 7 9 4 4 4 1 2012 4 3 8 10 5 3 4 1 2012
Belize NA NA NA NA NA NA NA NA NA NA 9 6 11 17 10 8 5 5 2011
Benin Yes 15 15 14 21 18 14 13 12 2011-2012 16 14 18 18 16 19 17 12 2011-2012
Bhutan NA NA NA NA NA NA NA NA NA NA 68 61 72 71 73 73 70 58 2010
Bolivia Yes NA NA NA NA NA NA NA NA NA 16 14 20 19 21 19 15 9 2008
Bosnia and Herzegovina Yes 6 6 6 13 6 5 4 5 2011-2012 5 4 5 12 5 3 4 3 2011-2012
Burkina Faso NA 34 23 39 39 39 42 35 23 2010 44 34 47 46 49 48 45 33 2010
Burundi NA 44 34 46 50 45 47 47 37 2010 73 56 75 78 78 75 73 62 2010
Cabo Verde NA 16 12 22 NA NA NA NA NA 2005 17 11 26 26 NA NA NA 11 2005
Cambodia Yes 22 12 25 30 26 22 26 10 2010 46 27 51 57 53 50 46 27 2010
Cameroon No 39 35 44 47 43 43 37 31 2011 47 40 54 51 54 51 46 35 2011
Central African Republic NA 75 72 78 79 80 76 73 69 2010 80 78 81 81 81 81 79 77 2010
Chad NA NA NA NA NA NA NA NA NA NA 62 66 61 63 61 61 61 65 2010
Comoros NA 17 14 19 17 21 19 17 13 2012 39 30 43 48 43 40 34 32 2012
Congo NA 62 62 61 61 67 64 63 56 2011-2012 73 74 72 72 77 76 72 69 2011-2012
Costa Rica NA NA NA NA NA NA NA NA NA NA 4 3 4 8 3 4 2 2 2011
C_te d'Ivoire NA 42 40 44 44 41 44 48 34 2011-2012 48 43 53 55 51 51 50 36 2011-2012
DR of the Congo No NA NA NA NA NA NA NA NA NA 76 67 80 82 80 80 77 62 2010
Dominican Republic NA NA NA NA NA NA NA NA NA NA 4 4 5 7 6 4 3 2 2009-2010
Egypt No NA NA NA NA NA NA NA NA NA 39 28 48 63 51 41 29 16 2008
Equatorial Guinea NA 52 46 60 56 58 61 59 41 2011 53 47 58 48 56 59 61 44 2011
Eritrea NA 45 35 51 46 55 53 45 32 2010 51 42 58 58 58 59 51 37 2010
Ethiopia Yes 45 25 51 58 55 52 43 25 2011 68 46 76 81 78 76 71 46 2011
Gabon NA 40 39 47 51 44 42 36 29 2012 50 49 61 63 54 52 47 40 2012
Gambia NA NA NA NA NA NA NA NA NA NA 75 63 87 88 83 81 76 54 2010
Georgia NA NA NA NA NA NA NA NA NA NA 7 6 8 8 10 8 6 4 2005
Ghana Yes 26 20 32 41 33 25 24 14 2011 44 36 54 65 54 50 41 22 2011
Guinea NA 66 57 73 81 73 68 61 54 2012 92 90 94 95 93 94 92 88 2012
Guinea-Bissau Yes NA NA NA NA NA NA NA NA NA 40 36 44 43 46 40 39 34 2010
Guyana NA 19 13 22 30 25 19 15 9 2009 16 8 20 24 21 18 13 9 2009
Haiti No 15 12 17 20 18 18 14 7 2012 17 14 19 23 21 18 15 11 2012
Honduras Yes 10 8 12 16 13 9 8 5 2011-2012 12 9 17 24 18 12 8 5 2011-2012
India Yes 42 33 47 53 50 48 40 26 2005-2006 47 37 52 55 54 54 47 30 2005-2006
Indonesia Yes 18 16 21 24 21 19 15 13 2012 35 30 40 42 38 35 31 28 2012
Iraq NA NA NA NA NA NA NA NA NA NA 51 46 64 66 55 52 46 40 2011
Jamaica Yes NA NA NA NA NA NA NA NA NA 5 4 6 7 8 5 2 2 2011
Jordan Yes NA NA NA NA NA NA NA NA NA 70 70 71 74 74 72 68 59 2012
Kazakhstan Yes 17 NA NA NA NA NA NA NA 2010-2011 12 11 14 17 15 12 10 9 2010-2011
Kenya No 44 36 47 54 52 45 41 36 2008-2009 53 34 59 67 67 59 49 32 2008-2009
Kiribati NA 60 51 67 65 66 66 57 44 2009 76 75 77 77 79 74 77 73 2009
Kyrgyzstan NA 50 48 52 45 48 51 59 50 2012 34 22 41 39 46 43 32 17 2012
Lao PDR NA 49 50 49 51 52 49 46 49 2011-2012 58 57 59 56 58 59 60 58 2011-2012
Lesotho No 48 37 53 59 52 55 48 33 2009 37 26 43 55 48 41 33 23 2009
Liberia NA 30 25 34 32 35 34 28 24 2007 59 52 65 64 69 62 56 49 2007
Madagascar Yes 46 41 47 53 51 47 46 39 2012-2013 45 38 47 52 47 45 45 40 2012-2013
Malawi Yes 13 8 14 16 14 13 14 10 2010 13 10 13 15 13 14 11 10 2010
Maldives NA 14 13 15 16 15 14 15 13 2009 31 18 37 40 37 36 27 15 2009
Mali No NA NA NA NA NA NA NA NA NA 87 84 89 88 88 88 89 83 2010
Marshall Islands NA 58 61 50 54 56 71 59 47 2007 56 48 73 69 70 49 51 37 2007
Mauritania Yes NA NA NA NA NA NA NA NA NA 38 32 43 47 45 41 32 29 2011
Mongolia Yes 9 6 13 13 12 8 6 5 2010 10 6 17 18 13 10 6 5 2010
Montenegro NA NA NA NA NA NA NA NA NA NA 11 9 14 23 11 8 10 4 2005
Morocco Yes NA NA NA NA NA NA NA NA NA 64 52 82 87 80 67 54 38 2003-2004
Mozambique Yes 20 14 24 21 25 27 19 11 2011 23 18 25 30 29 24 22 13 2011
Namibia Yes 41 31 51 63 54 44 33 23 2006-2007 35 22 47 58 48 43 27 13 2006-2007
Nepal Yes 22 20 22 26 23 22 20 19 2006 23 27 23 28 24 22 20 23 2006
Nicaragua Yes NA NA NA NA NA NA NA NA NA 14 10 20 28 17 12 9 6 2006-2007
Niger No 27 25 28 22 25 33 26 27 2012 60 49 62 59 63 65 62 51 2012
Nigeria Yes 25 19 29 31 31 27 23 15 2013 35 26 41 43 45 42 30 19 2013
Pakistan No 32 23 37 52 43 34 19 17 2012-2013 42 27 50 54 57 48 36 19 2012-2013
Philippines Yes NA NA NA NA NA NA NA NA NA 14 12 17 21 19 15 12 8 2008
Moldova Yes 13 10 15 25 15 14 10 7 2012 11 9 13 22 16 11 8 6 2012
Rwanda Yes 25 20 26 34 31 26 24 17 2010 56 40 59 66 63 59 56 40 2010
Saint Lucia NA NA NA NA NA NA NA NA NA NA 7 10 6 10 NA NA NA 6 2012
Samoa NA 46 34 48 53 48 43 48 39 2009 61 37 67 65 65 63 60 52 2009
Sao Tome and Principe NA 22 17 26 32 28 18 19 13 2008-2009 20 19 20 24 21 18 21 15 2008-2009
Senegal Yes 25 21 30 39 29 23 24 16 2010-2011 60 49 71 80 70 63 54 42 2010-2011
Serbia Yes 7 4 10 17 5 11 1 2 2010 3 1 5 11 4 2 1 0 2010
Sierra Leone Yes NA NA NA NA NA NA NA NA NA 73 62 80 82 80 80 75 53 2010
Solomon Islands NA 65 76 63 62 69 60 62 72 2007 69 65 70 66 71 68 71 68 2007
Somalia NA NA NA NA NA NA NA NA NA NA 76 68 80 85 83 80 67 65 2006
South Sudan NA NA NA NA NA NA NA NA NA NA 79 78 79 83 77 77 79 78 2010
Sri Lanka Yes NA NA NA NA NA NA NA NA NA 53 47 55 57 57 55 54 43 2006-2007
Sudan NA NA NA NA NA NA NA NA NA NA 47 38 52 69 60 49 36 29 2010
Suriname NA NA NA NA NA NA NA NA NA NA 13 10 19 22 16 11 9 6 2010
Swaziland NA 23 16 26 29 28 27 22 15 2010 28 14 33 42 40 30 24 12 2010
Tajikistan NA NA NA NA NA NA NA NA NA NA 60 51 63 66 65 61 58 48 2012
Thailand Yes NA NA NA NA NA NA NA NA NA 13 10 15 18 20 14 10 6 2012
Macedonia NA NA NA NA NA NA NA NA NA NA 15 7 24 36 21 12 5 2 2011
Timor-Leste NA 81 86 79 81 80 79 80 83 2009-2010 86 89 85 81 85 88 88 89 2009-2010
Togo NA 21 16 22 NA NA NA NA NA 2012 43 39 47 48 49 47 44 32 2010
Trinidad and Tobago NA NA NA NA NA NA NA NA NA 2011 8 NA NA 12 10 9 5 3 2006
Tunisia No NA NA NA NA NA NA NA NA 2012 30 24 44 49 38 31 23 14 2011-2012
Turkey Yes NA NA NA NA NA NA NA NA 2010 25 21 36 43 35 28 18 7 2008
Tuvalu NA 73 NA NA 75 73 74 71 73 2002 70 NA NA 71 68 68 65 78 2007
Uganda Yes 44 29 47 49 49 47 40 36 2013 58 46 61 58 61 63 67 47 2011
Ukraine Yes 9 8 14 17 9 10 7 7 2007 3 2 6 7 4 3 2 2 2012
Tanzania NA 38 27 42 46 46 42 37 25 2010-2011 54 43 58 61 59 60 57 36 2010
Vanuatu NA 60 69 55 60 58 56 65 62 NA 60 60 60 56 60 64 61 57 2013
Viet Nam NA NA NA NA NA NA NA NA NA NA 36 27 40 49 44 38 32 20 2011
Zambia Yes 49 43 54 49 57 60 52 34 NA 62 56 66 65 68 71 65 47 2007
Zimbabwe Yes 34 27 38 39 41 39 32 23 NA 40 29 46 52 49 46 34 25 2010-2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment