Skip to content

Instantly share code, notes, and snippets.

@basicavisual
Created December 3, 2015 19:20
Show Gist options
  • Save basicavisual/64c77fa4abee31af9916 to your computer and use it in GitHub Desktop.
Save basicavisual/64c77fa4abee31af9916 to your computer and use it in GitHub Desktop.
Embarazos adolescentes por municipio jalisciense en 2014
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Embarazos adolescentes Jalisco 2014</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
margin: 0;
background-color: lightGray;
font-family: Helvetica, Arial, sans-serif;
}
#container {
width: 700px;
margin-left: auto;
margin-right: auto;
margin-top: 50px;
padding: 50px;
background-color: white;
box-shadow: 3px 3px 5px 6px #ccc;
}
p {
font-size: 14px;
margin: 15px 0 10px 0;
}
a:link {
text-decoration: none;
color: gray;
}
a:hover {
text-decoration: underline;
}
a:visited {
color: gray;
}
a:active {
color: lightsalmon;
}
svg {
background-color: white;
}
g.bar text {
font-size: 11px;
font-weight: bold;
text-anchor: end;
opacity: 0;
}
g.bar:hover rect {
fill: palegreen;
}
g.bar:hover text {
opacity: 1;
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
.y.axis path,
.y.axis line {
opacity: 0;
}
</style>
</head>
<body>
<div id="container">
<h1>Porcentaje de embarazos adolescentes (15-19 años) por municipio jaliciense en 2014.</h1>
<p>Explica el número de nacidos vivos de una madre de 15-19 años, por cada 100 nacidos vivos. Datos extraídos de la Secretaría de Salud.</p>
</div>
<script type="text/javascript">
//dimensions
var w = 700;
var h = 2000;
var padding = 30;
var paddingLeft = 130;
//scales
var widthScale = d3.scale.linear()
.range([0, w - padding - paddingLeft]);
var heightScale = d3.scale.ordinal()
.rangeRoundBands([padding, h - padding], 0.1);
//set axes
var xAxis = d3.svg.axis()
.scale(widthScale)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(heightScale)
.orient("left");
//Render svg workspace
var svg = d3.select("#container")
.append("svg")
.attr("width", w)
.attr("height", h);
//call csv file
d3.csv("NacidosVivosRegistrados2014.csv", function(data){
//data sort
data.sort(function(a,b) {
return d3.descending(+a.perCent1519, +b.perCent1519)
});
//set domains
widthScale.domain([0, d3.max(data, function(d){
return +d.perCent1519;
}) ]);
heightScale.domain(data.map(function(d) { return d.Municipio; } ));
//bind data to groups (not bars)
var groups = svg.selectAll("g")
.data(data)
.enter()
.append("g")
.attr("class", "bar");
//add rects to groups
var rects = groups.append("rect")
.attr("x", paddingLeft)
.attr("y", function(d){
return heightScale(d.Municipio);
})
.attr("width", 0)
.attr("height", heightScale.rangeBand())
.attr("fill", "lightsalmon");
//add text
groups.append("text")
.attr("x", function(d) {
return paddingLeft + widthScale(d.perCent1519) - 3;
})
.attr("y", function(d) {
return heightScale(d.Municipio) + 11;
})
.text(function(d) {
return(d.perCent1519);
});
//transition
rects.transition()
.delay(function(d, i) {
return i * 50;
})
.duration(1000)
.attr("width", function(d) {
return widthScale(d.perCent1519);
});
//render axes
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(" + paddingLeft + "," + (h - padding) + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + paddingLeft + ",0)")
.call(yAxis);
});
</script>
</body>
</html>
Clave Municipio Región Nacimientos total 10 a 14 perCent1519 15 a 19 20 a 24 25 a 29 30 a 34 35 a 39 40 a 44 45 a 49 50 a 59 NO ESPECIFICADO Masculino Femenino Sin Información
- Jalisco 151,255 326 0.153 23,210 44,636 38,198 27,327 13,521 3,690 226 35 86 77,140 74,004 111
Municipio no especificado 216 0 0.097 21 64 52 47 25 7 0 0 0 99 117 0
1 Acatic 3 460 0 0.159 73 130 115 90 34 18 0 0 0 221 239 0
2 Acatlán de Juárez 12 440 0 0.191 84 160 97 57 29 10 1 1 1 227 212 1
3 Ahualulco de Mercado 9 402 0 0.142 57 121 107 79 29 8 1 0 0 218 184 0
4 Amacueca 6 123 1 0.098 12 29 44 21 12 3 0 0 1 66 55 2
5 Amatitán 9 296 0 0.105 31 89 82 53 28 10 2 1 0 163 133 0
6 Ameca 9 1,163 3 0.152 177 342 305 191 110 31 2 2 0 573 590 0
7 San Juanito de Escobedo 9 165 0 0.121 20 55 47 32 10 1 0 0 0 87 78 0
8 Arandas 3 1,570 0 0.106 167 441 413 312 166 63 7 1 0 808 760 2
9 El Arenal 9 420 1 0.181 76 133 85 70 42 11 1 0 1 211 209 0
10 Atemajac de Brizuela 6 167 0 0.210 35 58 29 28 16 1 0 0 0 78 89 0
11 Atengo 7 104 0 0.115 12 29 35 18 6 4 0 0 0 57 47 0
12 Atenguillo 9 68 0 0.103 7 25 18 13 4 0 1 0 0 35 33 0
13 Atotonilco El Alto 4 1,391 5 0.137 191 393 359 259 146 34 2 1 1 708 682 1
14 Atoyac 6 165 0 0.139 23 49 43 26 21 2 0 0 1 95 70 0
15 Autlán de Navarro 7 1,172 3 0.140 164 361 323 214 93 12 1 0 1 594 578 0
16 Ayotlán 4 698 0 0.146 102 194 178 134 69 21 0 0 0 342 356 0
17 Ayutla 7 231 1 0.139 32 58 77 36 19 7 1 0 0 132 99 0
18 La Barca 4 1,577 2 0.176 277 438 433 252 131 39 3 2 0 865 712 0
19 Bolaños 1 260 2 0.212 55 93 46 31 23 6 1 0 3 112 148 0
20 Cabo Corrientes 8 182 1 0.236 43 47 53 24 12 1 0 0 1 91 90 1
21 Casimiro Castillo 7 377 1 0.167 63 126 93 74 14 5 1 0 0 184 193 0
22 Cihuatlán 7 782 5 0.220 172 246 213 88 43 15 0 0 0 410 372 0
23 Zapotlán El Grande 6 2,036 6 0.149 304 597 557 377 146 44 5 0 0 1,051 984 1
24 Cocula 9 532 1 0.145 77 157 148 90 41 18 0 0 0 279 252 1
25 Colotlán 1 307 1 0.117 36 100 83 61 18 6 0 0 2 153 154 0
26 Concepción de Buenos Aires 5 97 0 0.165 16 19 22 23 12 2 1 2 0 46 51 0
27 Cuautitlán de García Barragán 7 313 0 0.204 64 92 67 49 35 6 0 0 0 155 158 0
28 Cuautla 7 36 1 0.111 4 9 12 7 3 0 0 0 0 13 23 0
29 Cuquío 11 331 1 0.106 35 95 75 67 38 18 0 0 2 175 156 0
30 Chapala 4 978 0 0.169 165 311 228 152 90 31 1 0 0 489 489 0
31 Chimaltitán 1 53 0 0.170 9 14 14 8 6 1 0 0 1 28 25 0
32 Chiquilistlán 7 133 1 0.128 17 57 20 20 15 3 0 0 0 67 66 0
33 Degollado 4 408 0 0.154 63 99 101 66 62 16 1 0 0 217 190 1
34 Ejutla 7 26 0 0.154 4 9 6 4 3 0 0 0 0 13 13 0
35 Encarnación de Díaz 2 978 0 0.094 92 307 286 176 99 16 2 0 0 483 495 0
36 Etzatlán 9 378 0 0.143 54 95 119 73 24 12 1 0 0 193 185 0
37 El Grullo 7 474 0 0.154 73 127 125 91 48 10 0 0 0 235 239 0
38 Guachinango 9 60 0 0.200 12 21 10 10 6 1 0 0 0 23 37 0
39 Guadalajara 13 28,945 52 0.139 4,013 8,299 7,347 5,656 2,726 781 53 4 14 14,786 14,143 16
40 Hostotipaquillo 9 185 0 0.178 33 54 52 31 12 2 1 0 0 96 89 0
41 Huejúcar 1 80 0 0.100 8 22 16 20 9 3 1 0 1 47 33 0
42 Huejuquilla El Alto 1 216 1 0.157 34 62 48 40 26 3 0 2 0 110 106 0
43 La Huerta 7 401 2 0.182 73 124 100 67 25 9 1 0 0 202 199 0
44 Ixtlahuacán de los Membrillos 12 1,010 2 0.217 219 301 234 143 90 20 1 0 0 527 482 1
45 Ixtlahuacán del Río 11 386 1 0.137 53 98 106 66 51 9 2 0 0 185 199 2
46 Jalostotitlán 3 707 2 0.105 74 175 218 129 78 27 2 0 2 376 330 1
47 Jamay 4 479 1 0.177 85 151 119 86 29 8 0 0 0 250 229 0
48 Jesús María 3 349 0 0.146 51 112 83 52 39 11 1 0 0 177 172 0
49 Jilotlán de los Dolores 5 153 0 0.176 27 49 40 23 11 3 0 0 0 73 80 0
50 Jocotepec 4 966 2 0.180 174 300 235 169 72 12 2 0 0 483 482 1
51 Juanacatlán 11 324 2 0.160 52 93 75 65 30 7 0 0 0 170 154 0
52 Juchitlán 7 103 0 0.155 16 25 31 16 10 5 0 0 0 57 46 0
53 Lagos de Moreno 2 3,609 3 0.133 481 1,103 967 662 301 87 5 0 0 1,822 1,786 1
54 El Limón 7 70 0 0.043 3 27 19 14 6 1 0 0 0 32 38 0
55 Magdalena 9 445 2 0.157 70 126 122 68 40 12 5 0 0 227 218 0
56 Santa María del Oro 5 27 0 0.185 5 1 6 9 1 3 2 0 0 11 16 0
57 La Manzanilla de la Paz 5 58 0 0.086 5 16 20 8 6 3 0 0 0 28 30 0
58 Mascota 8 222 0 0.140 31 66 58 34 27 6 0 0 0 110 112 0
59 Mazamitla 5 276 1 0.156 43 76 77 48 23 6 2 0 0 129 147 0
60 Mexticacán 3 103 0 0.097 10 40 29 14 10 0 0 0 0 52 51 0
61 Mezquitic 1 459 1 0.207 95 151 101 66 30 13 0 0 2 244 213 2
62 Mixtlán 9 60 2 0.117 7 18 12 8 8 3 2 0 0 29 31 0
63 Ocotlán 4 1,987 6 0.177 352 618 495 316 161 34 3 1 1 1,025 956 6
64 Ojuelos de Jalisco 2 649 1 0.125 81 195 177 91 80 22 1 1 0 310 339 0
65 Pihuamo 5 200 0 0.215 43 60 51 28 12 4 1 0 1 118 82 0
66 Poncitlán 4 1,232 2 0.188 231 433 268 197 72 24 3 1 1 615 614 3
67 Puerto Vallarta 8 5,145 10 0.162 836 1,599 1,316 859 406 113 3 0 3 2,680 2,464 1
68 Villa Purificación 7 192 1 0.224 43 75 44 18 9 2 0 0 0 96 96 0
69 Quitupan 5 133 0 0.143 19 41 29 18 19 7 0 0 0 65 68 0
70 El Salto 11 3,791 12 0.217 821 1,298 843 498 248 68 3 0 0 1,959 1,828 4
71 San Cristóbal de la Barranca 10 58 0 0.121 7 12 17 11 9 2 0 0 0 31 27 0
72 San Diego de Alejandría 2 118 0 0.076 9 30 38 24 15 1 1 0 0 55 63 0
73 San Juan de los Lagos 2 1,629 2 0.133 216 488 429 289 154 47 4 0 0 842 783 4
74 San Julián 3 298 0 0.077 23 94 78 61 28 13 1 0 0 143 155 0
75 San Marcos 9 82 0 0.159 13 25 22 12 8 1 1 0 0 43 39 0
76 San Martín de Bolaños 1 53 0 0.302 16 12 9 12 4 0 0 0 0 23 30 0
77 San Martín Hidalgo 9 444 1 0.140 62 108 112 89 46 26 0 0 0 217 227 0
78 San Miguel El Alto 3 583 1 0.132 77 188 132 121 53 10 1 0 0 286 297 0
79 Gómez Farías 6 273 0 0.139 38 92 68 49 20 6 0 0 0 140 133 0
80 San Sebastián del Oeste 8 88 0 0.205 18 26 19 19 4 1 1 0 0 44 44 0
81 Santa María de los Ángeles 1 54 0 0.093 5 16 15 7 6 4 0 0 1 25 29 0
82 Sayula 6 717 3 0.160 115 206 181 133 60 13 1 0 5 359 355 3
83 Tala 9 1,423 8 0.202 287 396 345 265 90 29 2 1 0 688 735 0
84 Talpa de Allende 8 249 0 0.185 46 64 62 47 24 6 0 0 0 113 136 0
85 Tamazula de Gordiano 5 737 2 0.144 106 230 204 117 66 10 2 0 0 372 360 5
86 Tapalpa 6 503 2 0.223 112 159 104 69 37 15 1 0 4 259 242 2
87 Tecalitlán 5 289 0 0.159 46 89 81 33 31 8 0 0 1 153 136 0
88 Tecolotlán 7 288 0 0.163 47 89 66 52 26 8 0 0 0 145 143 0
89 Techaluta de Montenegro 6 67 0 0.194 13 20 14 14 5 1 0 0 0 34 33 0
90 Tenamaxtlán 7 112 1 0.125 14 32 23 25 12 5 0 0 0 63 49 0
91 Teocaltiche 2 779 0 0.141 110 190 222 137 86 30 4 0 0 372 405 2
92 Teocuitatlán de Corona 6 169 0 0.154 26 46 49 29 14 4 0 0 1 79 90 0
93 Tepatitlán de Morelos 3 3,045 3 0.111 337 875 844 584 298 90 10 1 3 1,518 1,523 4
94 Tequila 9 871 2 0.135 118 273 210 157 80 29 2 0 0 452 418 1
95 Teuchitlán 9 163 1 0.209 34 52 38 27 10 1 0 0 0 85 78 0
96 Tizapán El Alto 4 390 0 0.174 68 118 77 86 34 7 0 0 0 187 203 0
97 Tlajomulco de Zúñiga 12 10,193 40 0.169 1,726 2,999 2,475 1,828 903 207 11 1 3 5,136 5,043 14
98 Tlaquepaque 12 13,140 29 0.174 2,291 4,078 3,119 2,241 1,061 296 14 2 9 6,760 6,373 7
99 Tolimán 6 230 1 0.170 39 68 58 37 23 3 1 0 0 128 102 0
100 Tomatlán 8 694 2 0.206 143 217 142 117 58 11 2 1 1 367 327 0
101 Tonalá 11 9,557 26 0.176 1,678 3,062 2,285 1,526 760 209 4 3 4 4,889 4,666 2
102 Tonaya 7 95 0 0.126 12 24 25 24 9 1 0 0 0 52 43 0
103 Tonila 6 104 1 0.173 18 31 27 19 6 2 0 0 0 51 53 0
104 Totatiche 1 63 0 0.095 6 23 21 9 1 3 0 0 0 37 26 0
105 Tototlán 4 411 4 0.187 77 118 89 72 37 13 1 0 0 202 208 1
106 Tuxcacuesco 7 92 0 0.098 9 23 31 22 5 2 0 0 0 44 48 0
107 Tuxcueca 4 117 0 0.120 14 40 32 13 13 3 1 0 1 53 64 0
108 Tuxpan 6 651 1 0.154 100 198 197 89 47 18 1 0 0 344 307 0
109 Unión de San Antonio 2 289 0 0.131 38 85 73 59 26 7 0 1 0 154 135 0
110 Unión de Tula 7 233 0 0.120 28 66 69 38 27 5 0 0 0 126 107 0
111 Valle de Guadalupe 3 144 0 0.153 22 39 40 29 11 2 0 0 1 61 83 0
112 Valle de Juárez 5 75 0 0.080 6 33 18 11 6 1 0 0 0 34 41 0
113 San Gabriel 6 342 1 0.146 50 103 87 56 29 12 3 0 1 175 167 0
114 Villa Corona 12 344 2 0.145 50 116 77 66 25 7 1 0 0 166 178 0
115 Villa Guerrero 1 118 0 0.161 19 33 24 22 16 4 0 0 0 65 53 0
116 Villa Hidalgo 2 345 0 0.072 25 115 99 60 37 9 0 0 0 176 168 1
117 Cañadas de Obregón 3 60 0 0.100 6 23 12 14 3 2 0 0 0 28 31 1
118 Yahualica de González Gallo 3 401 1 0.132 53 109 120 69 35 14 0 0 0 211 190 0
119 Zacoalco de Torres 6 578 3 0.154 89 175 165 76 53 13 2 1 1 302 275 1
120 Zapopan 10 24,009 40 0.136 3,256 6,520 6,221 4,873 2,453 610 24 5 7 12,277 11,722 10
121 Zapotiltic 6 613 1 0.147 90 204 162 97 46 13 0 0 0 339 273 1
122 Zapotitlán de Vadillo 6 146 0 0.219 32 33 38 26 14 2 1 0 0 80 66 0
123 Zapotlán del Rey 4 319 2 0.182 58 79 79 64 31 6 0 0 0 155 164 0
124 Zapotlanejo 11 1,477 3 0.180 266 394 374 281 121 38 0 0 0 721 754 2
125 San Ignacio Cerro Gordo 3 402 1 0.097 39 100 122 78 50 9 0 0 3 192 208 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment