Skip to content

Instantly share code, notes, and snippets.

@teresagd
Created February 21, 2017 18:43
Show Gist options
  • Save teresagd/1ce5aedb4bf30c5acfe5e2adbe66db8b to your computer and use it in GitHub Desktop.
Save teresagd/1ce5aedb4bf30c5acfe5e2adbe66db8b to your computer and use it in GitHub Desktop.
Practica D3 Utad-EDS
license: mit
year country_name life_expectancy fertility_rate population GDP region_value
1 2014 United Arab Emirates 77.3681707317073 1.784 9086139 44238.5997740128 Middle East & North Africa
2 2014 Afghanistan 60.3744634146342 4.843 31627506 633.947864294639 South Asia
3 2014 Antigua and Barbuda 75.9376341463415 2.075 90900 13432.0792079208 Latin America & Caribbean
4 2014 Albania 77.8304634146342 1.784 2893654 4568.56882650826 Europe & Central Asia
5 2014 Armenia 74.6757073170732 1.531 3006154 3861.91557044458 Europe & Central Asia
6 2014 Angola 52.2668780487805 6.08 24227524 5232.76230029543 Sub-Saharan Africa
7 2014 Argentina 76.1586097560976 2.322 42980026 12324.9387857728 Latin America & Caribbean
8 2014 Austria 81.3365853658537 1.44 8541575 51322.6399728758 Europe & Central Asia
9 2014 Australia 82.2512195121951 1.859 23464086 61995.8296976 East Asia & Pacific
10 2014 Azerbaijan 70.7632195121951 2 9535079 7886.45914367274 Europe & Central Asia
11 2014 Bosnia and Herzegovina 76.433243902439 1.263 3817554 4852.31864873611 Europe & Central Asia
12 2014 Barbados 75.4964146341463 1.794 283380 15360.0618007811 Latin America & Caribbean
13 2014 Bangladesh 71.6259024390244 2.175 159077513 1086.80008676935 South Asia
14 2014 Belgium 80.5878048780488 1.75 11231213 47346.792823245 Europe & Central Asia
15 2014 Burkina Faso 58.5884634146341 5.521 17589198 696.856206759424 Sub-Saharan Africa
16 2014 Bulgaria 75.4073170731707 1.48 7223938 7853.33519086217 Europe & Central Asia
17 2014 Bahrain 76.6832682926829 2.056 1361930 24514.9991306142 Middle East & North Africa
18 2014 Burundi 56.6920243902439 5.948 10816860 286.002335872952 Sub-Saharan Africa
19 2014 Benin 59.5105853658537 4.766 10598482 915.926640778784 Sub-Saharan Africa
20 2014 Brunei Darussalam 78.8095853658537 1.874 417394 41023.8898817215 East Asia & Pacific
21 2014 Bolivia 68.344 2.968 10561887 3124.08543446758 Latin America & Caribbean
22 2014 Brazil 74.4018780487805 1.79 206077898 11728.7993875108 Latin America & Caribbean
23 2014 Bahamas, The 75.2336585365854 1.872 383054 22497.4497068298 Latin America & Caribbean
24 2014 Bhutan 69.471243902439 2.027 765008 2560.52213174131 South Asia
25 2014 Botswana 64.429243902439 2.836 2219937 7153.44785946834 Sub-Saharan Africa
26 2014 Belarus 72.9756097560976 1.62 9483000 8025.30435552468 Europe & Central Asia
27 2014 Belize 70.0774390243902 2.579 351706 4884.36856220286 Latin America & Caribbean
28 2014 Canada 81.9566097560976 1.61 35543658 50185.4814970346 North America
29 2014 Congo, Dem. Rep. 58.6591951219512 6.006 74877030 437.814931177839 Sub-Saharan Africa
30 2014 Central African Republic 50.6577804878049 4.286 4804316 354.451901072874 Sub-Saharan Africa
31 2014 Congo, Rep. 62.3111463414634 4.869 4504962 3147.07152408764 Sub-Saharan Africa
32 2014 Switzerland 82.8487804878049 1.52 8188649 85814.5885735953 Europe & Central Asia
33 2014 Cote d'Ivoire 51.5595853658537 5.001 22157107 1544.32133718797 Sub-Saharan Africa
34 2014 Chile 81.4961951219512 1.761 17762647 14566.1490549222 Latin America & Caribbean
35 2014 Cameroon 55.492756097561 4.704 22773014 1407.40341322234 Sub-Saharan Africa
36 2014 China 75.7822682926829 1.562 1364270000 7683.50203795784 East Asia & Pacific
37 2014 Colombia 73.9931463414634 1.897 47791393 7918.07890039352 Latin America & Caribbean
38 2014 Costa Rica 79.4027073170732 1.819 4757606 10544.7200314114 Latin America & Caribbean
39 2014 Cabo Verde 73.147 2.303 513906 3661.16875840904 Sub-Saharan Africa
40 2014 Cyprus 80.1315609756098 1.446 1153658 27340.8838161118 Europe & Central Asia
41 2014 Czech Republic 78.2756097560976 1.46 10525347 19744.5586092159 Europe & Central Asia
42 2014 Germany 80.8439024390244 1.39 80982500 47902.6528842516 Europe & Central Asia
43 2014 Djibouti 62.015512195122 3.195 876174 1812.42538582519 Middle East & North Africa
44 2014 Denmark 80.5487804878049 1.67 5643475 61330.9126252044 Europe & Central Asia
45 2014 Dominican Republic 73.5000243902439 2.48 10405943 6268.63248273048 Latin America & Caribbean
46 2014 Algeria 74.8080975609756 2.857 38934334 5484.0668056148 Middle East & North Africa
47 2014 Ecuador 75.872487804878 2.542 15902916 6432.29581291884 Latin America & Caribbean
48 2014 Estonia 77.2390243902439 1.52 1314545 19941.4526982953 Europe & Central Asia
49 2014 Egypt, Arab Rep. 71.1217073170732 3.338 89579670 3365.70742057477 Middle East & North Africa
50 2014 Spain 83.0780487804878 1.27 46480882 29718.5002155441 Europe & Central Asia
51 2014 Ethiopia 64.0350243902439 4.395 96958732 573.565960346077 Sub-Saharan Africa
52 2014 Finland 81.1292682926829 1.75 5461512 49887.8969739642 Europe & Central Asia
53 2014 Fiji 70.0891219512195 2.564 886450 5042.37139569794 East Asia & Pacific
54 2014 Micronesia, Fed. Sts. 69.1010731707317 3.243 104044 3057.09123063319 East Asia & Pacific
55 2014 France 82.3731707317073 1.99 66495940 42696.7788294314 Europe & Central Asia
56 2014 Gabon 64.3833902439024 3.909 1687673 10772.0617537637 Sub-Saharan Africa
57 2014 United Kingdom 81.0560975609756 1.83 64613160 46412.1172713997 Europe & Central Asia
58 2014 Grenada 73.3663170731707 2.149 106349 8570.66339581455 Latin America & Caribbean
59 2014 Georgia 74.6686341463415 1.816 3727000 4429.65007451491 Europe & Central Asia
60 2014 Ghana 61.3116341463415 4.168 26786598 1441.63645311166 Sub-Saharan Africa
61 2014 Gambia, The 60.2284390243902 5.717 1928201 440.370389176931 Sub-Saharan Africa
62 2014 Guinea 58.7334390243902 5.013 12275527 539.615774988756 Sub-Saharan Africa
63 2014 Equatorial Guinea 57.6470487804878 4.835 820885 26144.9405009551 Sub-Saharan Africa
64 2014 Greece 81.2853658536585 1.3 10892413 21673.7810702225 Europe & Central Asia
65 2014 Guatemala 71.7224146341463 3.211 16015494 3666.57983772965 Latin America & Caribbean
66 2014 Guinea-Bissau 55.1600487804878 4.835 1800513 615.939682581074 Sub-Saharan Africa
67 2014 Guyana 66.4064146341463 2.558 763893 4028.1639914829 Latin America & Caribbean
68 2014 Hong Kong SAR, China 83.9804878048781 1.234 7241700 40215.4896458262 East Asia & Pacific
69 2014 Honduras 73.1357073170732 2.382 7961680 2434.280046303 Latin America & Caribbean
70 2014 Croatia 77.3292682926829 1.46 4238389 13480.6507536281 Europe & Central Asia
71 2014 Haiti 62.7474390243902 3.033 10572029 831.59052167163 Latin America & Caribbean
72 2014 Hungary 75.8731707317073 1.35 9866468 14117.9766762093 Europe & Central Asia
73 2014 Indonesia 68.8884878048781 2.463 254454778 3499.58873476515 East Asia & Pacific
74 2014 Ireland 81.1536585365854 1.96 4617225 55503.3272623334 Europe & Central Asia
75 2014 Israel 82.1536585365854 3.08 8215700 37582.8462414114 Middle East & North Africa
76 2014 India 68.0138048780488 2.427 1295291543 1576.81766887286 South Asia
77 2014 Iraq 69.3996829268293 4.566 35273293 6484.5293366572 Middle East & North Africa
78 2014 Iran, Islamic Rep. 75.3893170731708 1.707 78143644 5442.87477076039 Middle East & North Africa
79 2014 Iceland 82.0609756097561 1.93 327386 52036.7318144531 Europe & Central Asia
80 2014 Italy 82.690243902439 1.39 60789140 35365.1041218615 Europe & Central Asia
81 2014 Jamaica 75.6535121951219 2.046 2720554 5108.3570381199 Latin America & Caribbean
82 2014 Jordan 74.0521463414634 3.422 7416083 4830.97691525943 Middle East & North Africa
83 2014 Japan 83.5878048780488 1.42 127131800 38139.4223595003 East Asia & Pacific
84 2014 Kenya 61.5763658536585 4.334 44863583 1368.49113215797 Sub-Saharan Africa
85 2014 Kyrgyz Republic 70.4024390243902 3.2 5835500 1279.76978265986 Europe & Central Asia
86 2014 Cambodia 68.2122926829268 2.635 15328136 1094.57668777899 East Asia & Pacific
87 2014 Kiribati 65.9516829268293 3.73 110470 1684.32129210314 East Asia & Pacific
88 2014 Comoros 63.2568536585366 4.49 769991 841.205555826432 Sub-Saharan Africa
89 2014 Korea, Rep. 82.1558536585366 1.205 50423955 27989.3539925863 East Asia & Pacific
90 2014 Kuwait 74.5850243902439 2.105 3753121 43332.4062504589 Middle East & North Africa
91 2014 Kazakhstan 71.62 2.74 17289224 12806.5651078094 Europe & Central Asia
92 2014 Lao PDR 66.1173658536586 2.991 6689300 1754.89619550379 East Asia & Pacific
93 2014 Lebanon 79.3730975609756 1.714 5612096 8148.6391668339 Middle East & North Africa
94 2014 St. Lucia 75.0468536585366 1.89 183645 7548.19695406698 Latin America & Caribbean
95 2014 Liechtenstein 82.2609756097561 1.45 37286 178713.227991851 Europe & Central Asia
96 2014 Sri Lanka 74.7948048780488 2.083 20771000 3852.74206641873 South Asia
97 2014 Liberia 60.8344146341464 4.719 4396554 457.858586520261 Sub-Saharan Africa
98 2014 Lesotho 49.7005853658537 3.185 2109197 1203.69589289216 Sub-Saharan Africa
99 2014 Lithuania 73.9658536585366 1.59 2932367 16489.7289835331 Europe & Central Asia
100 2014 Luxembourg 82.2073170731707 1.55 556319 116612.884151875 Europe & Central Asia
101 2014 Latvia 74.1878048780488 1.52 1993782 15710.1677090724 Europe & Central Asia
102 2014 Morocco 74.0160975609756 2.515 33921203 3186.60875960434 Middle East & North Africa
103 2014 Moldova 71.4558780487805 1.256 3556397 2244.76376248334 Europe & Central Asia
104 2014 Montenegro 76.1807073170732 1.689 621810 7378.04227074613 Europe & Central Asia
105 2014 Madagascar 65.0856097560976 4.409 23571713 452.810394929053 Sub-Saharan Africa
106 2014 Macedonia, FYR 75.3423902439024 1.524 2075625 5453.28127512774 Europe & Central Asia
107 2014 Mali 57.9862682926829 6.229 17086022 819.621297242724 Sub-Saharan Africa
108 2014 Myanmar 65.8578536585366 2.204 53437159 1227.1372167517 East Asia & Pacific
109 2014 Mongolia 69.4639024390244 2.655 2909871 4201.73772175647 East Asia & Pacific
110 2014 Macao SAR, China 80.5530975609756 1.243 577914 96074.8369597196 East Asia & Pacific
111 2014 Mauritania 63.0165853658537 4.603 3969625 1370.98521248511 Sub-Saharan Africa
112 2014 Malta 81.7463414634146 1.38 427364 25125.0956185779 Middle East & North Africa
113 2014 Mauritius 74.1943902439024 1.43 1260934 10153.9382184867 Sub-Saharan Africa
114 2014 Maldives 76.7728292682927 2.123 401000 7716.20401546133 South Asia
115 2014 Malawi 62.7216341463415 5.129 16695253 362.693068268546 Sub-Saharan Africa
116 2014 Mexico 76.7218536585366 2.243 125385833 10353.4479828794 Latin America & Caribbean
117 2014 Malaysia 74.7182926829268 1.944 29901997 11305.9000976846 East Asia & Pacific
118 2014 Mozambique 55.0259512195122 5.359 27216276 623.197936625371 Sub-Saharan Africa
119 2014 Namibia 64.6801951219512 3.522 2402858 5349.44767556484 Sub-Saharan Africa
120 2014 Niger 61.4584878048781 7.599 19113728 431.381682137856 Sub-Saharan Africa
121 2014 Nigeria 52.7542682926829 5.65 177475986 3203.24429573261 Sub-Saharan Africa
122 2014 Nicaragua 74.8101463414634 2.264 6013913 1960.49090771313 Latin America & Caribbean
123 2014 Netherlands 81.3048780487805 1.68 16865008 52157.4068701887 Europe & Central Asia
124 2014 Norway 81.7512195121951 1.78 5137232 97005.4985619729 Europe & Central Asia
125 2014 Nepal 69.6046829268293 2.222 28174724 703.182570716641 South Asia
126 2014 New Zealand 81.4048780487805 1.92 4509700 44380.426584212 East Asia & Pacific
127 2014 Oman 77.0850975609756 2.774 4236057 19129.8442238053 Middle East & North Africa
128 2014 Panama 77.5951463414634 2.444 3867535 12712.4313236227 Latin America & Caribbean
129 2014 Peru 74.5255365853659 2.455 30973148 6490.18118975687 Latin America & Caribbean
130 2014 Papua New Guinea 62.6069268292683 3.757 7463577 2268.17253944302 East Asia & Pacific
131 2014 Philippines 68.2656341463415 2.977 99138690 2873.08818884252 East Asia & Pacific
132 2014 Pakistan 66.1833658536585 3.617 185044286 1320.55354981784 South Asia
133 2014 Poland 77.2536585365854 1.29 38011735 14341.8599344653 Europe & Central Asia
134 2014 West Bank and Gaza 72.9040243902439 4.176 4294682 2960.77800144929 Middle East & North Africa
135 2014 Portugal 80.7219512195122 1.21 10401062 22124.3672201026 Europe & Central Asia
136 2014 Paraguay 72.9217073170732 2.542 6552518 4712.87020536405 Latin America & Caribbean
137 2014 Qatar 78.5968048780488 2.026 2172065 94944.0855935367 Middle East & North Africa
138 2014 Romania 75.0634146341463 1.41 19908979 10020.2773322992 Europe & Central Asia
139 2014 Serbia 75.5341463414634 1.43 7130576 6200.17322102474 Europe & Central Asia
140 2014 Russian Federation 70.3658536585366 1.7 143819569 14051.599123979 Europe & Central Asia
141 2014 Rwanda 63.9656585365854 3.898 11341544 697.626501273706 Sub-Saharan Africa
142 2014 Saudi Arabia 74.3372195121951 2.765 30886545 24406.4764554706 Middle East & North Africa
143 2014 Solomon Islands 67.9308048780488 3.966 572171 2021.35921403919 East Asia & Pacific
144 2014 Seychelles 73.2292682926829 2.3 91400 15563.7942183676 Sub-Saharan Africa
145 2014 Sudan 63.4585365853658 4.353 39350274 2087.70054355486 Sub-Saharan Africa
146 2014 Sweden 81.9560975609756 1.89 9696110 59180.1989776727 Europe & Central Asia
147 2014 Singapore 82.6463414634146 1.25 5469724 56007.288209027 East Asia & Pacific
148 2014 Slovenia 80.519512195122 1.55 2061980 24020.6728561283 Europe & Central Asia
149 2014 Slovak Republic 76.7146341463415 1.34 5418649 18595.1511139028 Europe & Central Asia
150 2014 Sierra Leone 50.8787804878049 4.626 6315627 794.08708204712 Sub-Saharan Africa
151 2014 Senegal 66.3725853658537 5.09 14672557 1041.71746058997 Sub-Saharan Africa
152 2014 Somalia 55.3548048780488 6.463 10517569 536.911143630244 Sub-Saharan Africa
153 2014 Suriname 71.1514390243903 2.36 538248 9680.11591367368 Latin America & Caribbean
154 2014 South Sudan 55.6822195121951 5.022 11911184 1115.09351496025 Sub-Saharan Africa
155 2014 Sao Tome and Principe 66.3846097560976 4.576 186342 1870.02102541527 Sub-Saharan Africa
156 2014 El Salvador 72.7545609756098 1.931 6107706 4102.0638517964 Latin America & Caribbean
157 2014 Swaziland 48.9347317073171 3.266 1269112 3539.91835063744 Sub-Saharan Africa
158 2014 Chad 51.5558048780488 6.156 13587053 1024.66835402191 Sub-Saharan Africa
159 2014 Togo 59.6558048780488 4.584 7115163 630.046061395906 Sub-Saharan Africa
160 2014 Thailand 74.4220243902439 1.512 67725979 5969.94011583791 East Asia & Pacific
161 2014 Tajikistan 69.5979756097561 3.49 8295840 1113.36635446715 Europe & Central Asia
162 2014 Timor-Leste 68.2591463414634 5.1 1212107 1154.18853286055 East Asia & Pacific
163 2014 Turkmenistan 65.5985365853659 2.301 5307188 8199.00938322259 Europe & Central Asia
164 2014 Tunisia 74.1439024390244 2.2 10996600 4328.90419734881 Middle East & North Africa
165 2014 Tonga 72.7921951219512 3.722 105586 4200.13204482265 East Asia & Pacific
166 2014 Turkey 75.163512195122 2.07 77523788 10303.6987055756 Europe & Central Asia
167 2014 Trinidad and Tobago 70.4405609756098 1.778 1354483 19325.3855038908 Latin America & Caribbean
168 2014 Tanzania 64.9439024390244 5.145 51822621 957.934534330474 Sub-Saharan Africa
169 2014 Ukraine 71.1865853658537 1.498 45362900 3104.65829575449 Europe & Central Asia
170 2014 Uganda 58.4664146341464 5.775 37782971 734.744015300391 Sub-Saharan Africa
171 2014 United States 78.9414634146341 1.8615 318907401 54539.6655752119 North America
172 2014 Uruguay 76.9861463414634 2.02 3419516 16737.973100697 Latin America & Caribbean
173 2014 Uzbekistan 68.3390243902439 2.2 30757700 2036.69172343054 Europe & Central Asia
174 2014 St. Vincent and the Grenadines 72.9368536585366 1.974 109360 6656.11571703379 Latin America & Caribbean
175 2014 Vietnam 75.6291219512195 1.961 90728900 2052.31908380089 East Asia & Pacific
176 2014 Vanuatu 71.9183170731707 3.347 258883 3147.96377889252 East Asia & Pacific
177 2014 Samoa 73.5118292682927 4.086 191845 4172.21710037661 East Asia & Pacific
178 2014 Kosovo 71.0975609756098 2.1 1812771 4073.81911686883 Europe & Central Asia
179 2014 Yemen, Rep. 63.8181951219512 4.16 26183676 1650.97459711297 Middle East & North Africa
180 2014 South Africa 57.1821219512195 2.363 54058647 6498.58899959915 Sub-Saharan Africa
181 2014 Zambia 60.0470487804878 5.353 15721343 1726.99284405704 Sub-Saharan Africa
182 2014 Zimbabwe 57.4983170731707 3.923 15245855 931.19818468692 Sub-Saharan Africa
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css?family=Amatic+SC:400,700" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="main.css">
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
</head>
<body>
<div id='title'>
<h2> Esperanza de vida mundial en el año 2014</h2>
<h4>Relación del Ratio de Fertilidad (eje y) respecto a la Esperanza de Vida (eje x) frente a la población mundial diferenciado por regiones<h4>
</div>
<div id='footer'> </div>
<script src="viz.js"></script>
</body>
</html>
.d3-tip {
line-height: 1;
font-weight: bold;
padding: 12px;
background: rgba(0, 0, 0, 0.8);
color: #fff;
border-radius: 2px;
}
/* Creates a small triangle extender for the tooltip */
.d3-tip:after {
box-sizing: border-box;
display: inline;
font-size: 10px;
width: 100%;
line-height: 1;
color: rgba(0, 0, 0, 0.8);
content: "\25BC";
position: absolute;
text-align: center;
}
/* Style northward tooltips differently */
.d3-tip.n:after {
margin: -1px 0 0 0;
top: 100%;
left: 0;
}
// Cargamos loa datos. Al eliminar los registros NA vemos que el año más reciente del que tenemos datos de la esperanza de vida y ratio de fertilidad es el 2014
d3.csv('datosWB2014.csv', function (error, csvData) {
var data = csvData.map(function (d) {
return {
pais: d.country_name,
ExpVida: +d.life_expectancy,
RatioFert: +d.fertility_rate,
Poblacion: +d.population,
Region: d.region_value
}
});
// Establecer tamaño de las burbujas
var minBubbleSize = 8, maxBubbleSize = 30;
//Establecer layaout
var margin = {
left: maxBubbleSize, top: maxBubbleSize,
bottom: maxBubbleSize, right: maxBubbleSize
};
var axisPadding = 10;
var graphWidth = 800, graphHeight = 500;
var totalWidth = graphWidth + margin.left + margin.right;
var totalHeight = graphHeight + margin.top + margin.bottom;
// Mapear variables
var EsperanzaVida = data.map(function (d) { return d.ExpVida; });
var RatioFertilidad = data.map(function (d) { return d.RatioFert; });
var Poblacion = data.map(function (d) { return d.Poblacion; });
var Regiones = data.map(function (d) { return d.Region; });
// Establecer escalas
var xScale = d3.scale.linear()
.domain([d3.min(EsperanzaVida), d3.max(EsperanzaVida)])
.range([0, graphWidth]);
var yScale = d3.scale.linear()
.domain([d3.max(RatioFertilidad), 0])
.range([0, graphHeight]);
var popDomain = [d3.min(Poblacion), d3.max(Poblacion)];
var popScale = d3.scale.linear()
.domain(popDomain)
.range([minBubbleSize, maxBubbleSize]);
var uRegiones = d3.set(Regiones).values();
var regionColor = d3.scale.ordinal()
.domain(uRegiones)
.range(d3.scale.category10().range());
var svg = d3.select("body").append('svg')
.attr('width', totalWidth)
.attr('height', totalHeight);
var yAxis = d3.svg.axis().scale(yScale).orient('left');
var yAxisNodes = svg.append('g')
.attr('transform', 'translate(' + (margin.left - axisPadding) + ',' + margin.top + ')')
.call(yAxis);
styleAxis(yAxisNodes);
var xAxis = d3.svg.axis().scale(xScale).orient('bottom');
var xAxisNodes = svg.append('g')
.attr('transform', 'translate(' + margin.left + ',' + (totalHeight - margin.bottom + axisPadding) + ')')
.call(xAxis);
styleAxis(xAxisNodes);
// Incluir leyenda
var tip = d3.tip()
.attr('class', 'd3-tip')
.offset([-10, 0])
.html(function(d) {
return "<strong> EspVida " + d.pais +":</strong> <br /> <span style='color:orange'>" + d.ExpVida + "</span>";
})
//Crear objeto svg
svg.call(tip);
svg.append('g')
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')
.selectAll('circle')
.data(data)
.enter()
.append('circle')
.on('mouseover', tip.show)
.on('mouseout', tip.hide)
.each(function (d) {
d3.select(this).attr({
cx: xScale(d.ExpVida),
cy: yScale(d.RatioFert),
r: popScale(d.Poblacion),
fill: regionColor(d.Region),
stroke: regionColor(d.Region),
'fill-opacity': 0.5,
});
});
// Definir leyenda
var legend = d3.select('svg')
.append("g")
.selectAll("g")
.data(regionColor.domain())
.enter()
.append('g')
.attr('class', 'legend')
.attr('transform', function(d, i) {
var height = 20;
var x = 640;
var y = i * height;
return 'translate(' + x + ',' + y + ')';
});
legend.append('rect')
.attr('width', 20)
.attr('height', 10)
.style('fill', regionColor)
.style('stroke', regionColor);
legend.append('text')
.attr('x', 30)
.attr('y', 10)
.text(function(d) { return d; });
});
// Insertar ejes
function styleAxis(axisNodes) {
axisNodes.selectAll('.domain')
.attr({
fill: 'none',
'stroke-width': 0.5,
stroke: 'black'
})
axisNodes.selectAll('.tick line')
.attr({
fill: 'none',
'stroke-width': 0.5,
stroke: 'black'
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment