Skip to content

Instantly share code, notes, and snippets.

@baderone
Last active September 9, 2015 10: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 baderone/926f7fcf35c294e657bf to your computer and use it in GitHub Desktop.
Save baderone/926f7fcf35c294e657bf to your computer and use it in GitHub Desktop.
Top 15 countries of origin of the tourists in Grisons, Switzerland

I have chosen the Canton of Grisons with famous tourist sites as for example St. Moritz for this exercise. You see from which countries how many people visited the Canton of Grisons in Switzerland in June 2015. I chose the month of June, because the long summer holiday in Switzerland starts not before July. Thus I can minimze potential bias for Swiss tourist in their own country. Nevertheless we see that most of the tourist are Swiss tourists followed by Germany and the UK

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Adding Labels</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: #CDD0E3;
font-family: Helvetica, Arial, sans-serif;
}
h1 {
font-size: 24px;
margin: 0;
}
p {
font-size: 14px;
margin: 10px 0 0 0;
}
svg {
background-color: #CDD0E3;
}
rect:hover {
fill: orange;
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
</style>
</head>
<body>
<h1>Top 15 countries of origin of the tourists in Grisons, Switzerland</h1>
<p>Arrivals of tourist in Grisons in June 2015 by country. Source: <a href="http://www.bfs.admin.ch/bfs/portal/de/index/themen/10.html">BFS Schweiz</a>, 2015</p>
<script type="text/javascript">
var w = 600;
var h = 500;
var padding = [ 20, 10, 20, 100 ]; //Top, right, bottom, left
var widthScale = d3.scale.linear()
.range([ 0, w - padding[1] - padding[3] ]);
var heightScale = d3.scale.ordinal()
.rangeRoundBands([ padding[0], h - padding[2] ], 0.1);
var xAxis = d3.svg.axis()
.scale(widthScale)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(heightScale)
.orient("left");
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
d3.csv("swiss tourism.csv", function(data) {
// New empty array
var subset = [];
// Loop through once for each row in the data set
for (var i=0; i < data.length; i++) {
// If this category matches what we want to extract…
if (data[i].id == "mod4") {
// …then save just the values (columns) we care about
// by appending a new object to the subset array
subset.push({
"countryoforigin": data[i].countryoforigin,
"grisonsarrival": data[i].grisonsarrival
});
}
}
subset.sort(function(a, b) {
return d3.descending(+a.grisonsarrival, +b.grisonsarrival);
});
widthScale.domain([ 0, d3.max(subset, function(d) {
return +d.grisonsarrival;
}) ]);
heightScale.domain(subset.map(function(d) { return d.countryoforigin; } ));
var rects = svg.selectAll("rect")
.data(subset)
.enter()
.append("rect");
rects.attr("x", padding[3])
.attr("y", function(d) {
return heightScale(d.countryoforigin);
})
.attr("width", function(d) {
return widthScale(d.grisonsarrival);
})
.attr("height", heightScale.rangeBand())
.append("title")
.text(function(d) {
return "In June 2015, " + d.grisonsarrival + "people of " + d.countryoforigin + " visited the Canton of Grisons";
});
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(" + padding[3] + "," + (h - padding[2]) + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + (padding[3] - 5) + ",0)")
.call(yAxis);
});
</script>
</body>
</html>
id countryoforigin time grisonsarrival grisonsnights grisonsduration lucernearrivals lucernenights lucerneduration bernesealpsarrivals bernesealpsnights bernesealpsduration tessinarrivals tessinnights tessinduration bernarrivals bernnights bernduration zuricharrivals zurichnights zurichduration baselarrivals baselnights baselduration genevaarrivals genevanights genevaduration
mod4 Switzerland June15 70784 151242 2.0999999 77933 133195 1.7 67316 128828 1.9 67154 146375 2.2 30969 49892 1.6 98820 159424 1.6 28628 46419 1.6 26718 51478 1.9
mod4 Germany June15 20131 58572 2.9000001 15088 31836 2.0999999 8071 21941 2.7 9458 24377 2.5999999 6658 12343 1.9 35769 61732 1.7 11578 20780 1.8 5233 9570 1.8
mod4 United States June15 4210 7916 1.9 20797 39744 1.9 13199 30207 2.3 3725 8473 2.3 2713 5354 2 28756 53402 1.9 6006 17132 2.9000001 12301 28378 2.3
mod4 UK June15 4737 11650 2.5 6586 13939 2.0999999 9433 31983 3.4000001 2382 5588 2.3 1348 2396 1.8 18275 30553 1.7 5243 10908 2.0999999 12258 22243 1.8
mod4 China June15 907 1144 1.3 40522 44705 1.1 26019 32085 1.2 1936 2712 1.4 2791 3318 1.2 19242 24957 1.3 1321 2235 1.7 6701 10450 1.6
mod4 India June15 533 886 1.7 15831 36439 2.3 9422 22521 2.4000001 1194 2032 1.7 304 646 2.0999999 18268 37531 2.0999999 714 2039 2.9000001 1999 5216 2.5999999
mod4 France June15 1213 1872 1.5 2150 3813 1.8 1895 3445 1.8 1986 3673 1.8 1162 1869 1.6 7932 12661 1.6 4307 7612 1.8 11428 18391 1.6
mod4 Italy June15 2189 4961 2.3 2551 4162 1.6 1462 2297 1.6 7986 13346 1.7 916 1711 1.9 6700 12252 1.8 2851 5382 1.9 3522 6253 1.8
mod4 Japan June15 3551 5862 1.7 1246 1765 1.4 9446 14795 1.6 297 692 2.3 1365 1785 1.3 5204 7603 1.5 598 1384 2.3 2380 5668 2.4000001
mod4 the Netherlands June15 1717 6193 3.5999999 3365 5304 1.6 1590 4270 2.7 1799 3589 2 527 866 1.6 3921 6925 1.8 1722 2902 1.7 2124 3842 1.8
mod4 Belgium June15 1410 8788 6.1999998 1875 3189 1.7 491 1622 3.3 1557 2522 1.6 345 589 1.7 2047 3478 1.7 1272 2374 1.9 2510 4497 1.8
mod4 Austria June15 1721 3784 2.2 1591 3223 2 773 1630 2.0999999 1048 2637 2.5 677 1333 2 5799 10114 1.7 1017 2267 2.2 734 1424 1.9
mod4 Spain June15 297 549 1.8 896 1907 2.0999999 866 1586 1.8 593 1480 2.5 664 1259 1.9 6566 11210 1.7 1068 2538 2.4000001 4043 7291 1.8
mod4 Australia June15 1164 1709 1.5 4573 8855 1.9 1626 3947 2.4000001 597 1356 2.3 365 699 1.9 4425 8770 2 486 1047 2.2 1561 3849 2.5
mod4 South Korea June15 108 146 1.4 3266 4474 1.4 10367 13674 1.3 226 340 1.5 727 981 1.3 2517 3497 1.4 463 879 1.9 622 1357 2.2
mod3 Canada June15 469 777 1.7 1447 2853 2 930 2127 2.3 431 895 2.0999999 290 536 1.8 3689 8425 2.3 503 1177 2.3 2200 5307 2.4000001
mod3 Russia June15 192 463 2.4000001 701 1514 2.2 340 711 2.0999999 635 1580 2.5 261 644 2.5 3174 6671 2.0999999 375 903 2.4000001 2198 4961 2.3
mod3 Saudi Arabia June15 110 132 1.2 380 996 2.5999999 2273 6247 2.7 443 1171 2.5999999 56 152 2.7 1238 2618 2.0999999 121 375 3.0999999 2201 6722 3.0999999
mod3 Taiwan June15 1234 1415 1.1 3577 4026 1.1 4469 6332 1.4 1118 1199 1.1 1279 1398 1.1 1448 2049 1.4 87 222 2.5999999 484 766 1.6
mod3 Brasil June15 314 585 1.9 1283 2475 1.9 656 1340 2 449 919 2 561 1038 1.9 2911 6097 2.0999999 299 1051 3.5 1568 4773 3
mod3 Israel June15 333 638 1.9 457 915 2 481 1254 2.5999999 312 818 2.5999999 146 352 2.4000001 2205 4282 1.9 1786 6761 3.8 806 1902 2.4000001
mod3 Hongkong June15 482 756 1.6 3188 4134 1.3 2038 3301 1.6 174 300 1.7 349 479 1.4 1704 3462 2 136 362 2.7 683 1287 1.9
mod3 Singapur June15 201 322 1.6 1451 2527 1.7 1469 2717 1.8 125 307 2.5 238 372 1.6 3292 5315 1.6 151 533 3.5 787 1900 2.4000001
mod3 United Arab Emirates June15 88 163 1.9 475 1215 2.5999999 1414 3846 2.7 211 524 2.5 51 137 2.7 1865 3714 2 102 378 3.7 1555 3407 2.2
mod3 Other African Countires June15 21 43 2 69 189 2.7 71 248 3.5 87 363 4.1999998 53 111 2.0999999 621 1583 2.5 205 491 2.4000001 2042 9552 4.6999998
mod3 Poland June15 196 374 1.9 444 1618 3.5999999 200 583 2.9000001 237 594 2.5 195 571 2.9000001 1687 3485 2.0999999 430 1463 3.4000001 547 1306 2.4000001
mod3 Other Southeast Asian Countries June15 70 89 1.3 1092 1361 1.2 818 1261 1.5 142 392 2.8 233 448 1.9 1579 2914 1.8 132 338 2.5999999 1314 4143 3.2
mod3 Sweden June15 355 699 2 422 816 1.9 300 581 1.9 407 726 1.8 170 309 1.8 1945 3214 1.7 424 819 1.9 977 2179 2.2
mod3 Thailand June15 128 152 1.2 1324 2007 1.5 1445 2526 1.7 306 403 1.3 242 414 1.7 1509 2669 1.8 109 270 2.5 472 1531 3.2
mod3 Portugal June15 86 195 2.3 238 500 2.0999999 127 232 1.8 209 494 2.4000001 217 440 2 1137 2261 2 213 445 2.0999999 1489 2742 1.8
mod3 Other European Countries June15 120 409 3.4000001 362 794 2.2 483 863 1.8 236 432 1.8 419 734 1.8 1139 1906 1.7 222 429 1.9 675 1521 2.3
mod3 Czech Republic June15 226 553 2.4000001 378 758 2 160 350 2.2 168 518 3.0999999 241 444 1.8 963 2616 2.7 255 598 2.3 334 678 2
mod3 Hungary June15 60 173 2.9000001 479 1273 2.7 206 344 1.7 157 337 2.0999999 56 221 3.9000001 1008 2608 2.5999999 227 701 3.0999999 306 867 2.8
mod3 Turkey June15 48 86 1.8 127 185 1.5 77 207 2.7 157 422 2.7 140 329 2.4000001 1553 2844 1.8 368 826 2.2 767 1980 2.5999999
mod3 Denmark June15 169 231 1.4 308 519 1.7 183 387 2.0999999 218 465 2.0999999 107 199 1.9 1097 1841 1.7 411 959 2.3 586 1334 2.3
mod3 Norway June15 252 423 1.7 289 563 1.9 437 832 1.9 200 336 1.7 106 186 1.8 999 1853 1.9 213 404 1.9 659 1674 2.5
mod3 Other Central American Countries June15 17 67 3.9000001 414 755 1.8 267 613 2.3 134 358 2.7 62 113 1.8 658 1286 2 86 323 3.8 711 2930 4.0999999
mod3 Finland June15 252 496 2 217 390 1.8 225 415 1.8 206 351 1.7 106 188 1.8 1251 1980 1.6 160 344 2.2 460 1179 2.5999999
mod3 Malaysia June15 62 90 1.5 864 1447 1.7 358 615 1.7 126 177 1.4 205 312 1.5 1396 2271 1.6 123 303 2.5 343 1005 2.9000001
mod3 Indonesia June15 90 116 1.3 672 1064 1.6 368 565 1.5 69 136 2 38 64 1.7 1681 3025 1.8 83 184 2.2 399 1096 2.7
mod3 Rumania June15 57 114 2 177 317 1.8 58 106 1.8 166 385 2.3 155 343 2.2 1105 2632 2.4000001 180 377 2.0999999 511 1100 2.2
mod3 Other South American Countries June15 80 121 1.5 109 226 2.0999999 63 141 2.2 198 434 2.2 67 122 1.8 805 1485 1.8 136 329 2.4000001 690 2786 4
mod3 Other West Asian Countries June15 12 19 1.6 159 383 2.4000001 69 134 1.9 114 272 2.4000001 41 102 2.5 552 1104 2 89 248 2.8 955 3178 3.3
mod3 Irland June15 58 133 2.3 166 370 2.2 122 374 3.0999999 93 228 2.5 56 85 1.5 1011 1749 1.7 322 727 2.3 703 1261 1.8
mod3 Luxemburg June15 193 609 3.2 320 670 2.0999999 187 622 3.3 215 632 2.9000001 81 106 1.3 572 993 1.7 276 424 1.5 442 806 1.8
mod3 Argentina June15 41 61 1.5 157 269 1.7 174 359 2.0999999 223 690 3.0999999 105 180 1.7 840 1745 2.0999999 139 343 2.5 502 1545 3.0999999
mod3 South Africa June15 58 72 1.2 217 532 2.5 271 740 2.7 62 126 2 42 138 3.3 652 1423 2.2 99 297 3 374 1559 4.1999998
mod3 New Zealand June15 79 170 2.2 482 1028 2.0999999 273 640 2.3 96 219 2.3 56 130 2.3 647 1243 1.9 69 139 2 341 900 2.5999999
mod3 Greece June15 63 106 1.7 46 71 1.5 41 86 2.0999999 166 378 2.3 45 103 2.3 847 1691 2 206 439 2.0999999 725 1672 2.3
mod3 Mexico June15 7 8 1.1 158 267 1.7 116 173 1.5 53 107 2 69 139 2 880 1739 2 149 394 2.5999999 559 1373 2.5
mod3 Ukraine June15 24 33 1.4 136 338 2.5 195 326 1.7 137 221 1.6 50 98 2 499 1073 2.2 74 136 1.8 517 1171 2.3
mod3 Kuwait June15 22 32 1.5 112 323 2.9000001 495 1332 2.7 119 255 2.0999999 14 16 1.1 289 700 2.4000001 47 97 2.0999999 419 983 2.3
mod3 Slovakia June15 82 202 2.5 115 277 2.4000001 53 97 1.8 61 150 2.5 49 128 2.5999999 519 1441 2.8 53 193 3.5999999 108 275 2.5
mod3 Other North African Countries June15 18 35 1.9 52 166 3.2 12 19 1.6 44 75 1.7 15 62 4.0999999 188 413 2.2 33 145 4.4000001 613 2422 4
mod3 Bulgaria June15 11 44 4 121 198 1.6 65 79 1.2 55 247 4.5 48 75 1.6 405 1289 3.2 70 179 2.5999999 227 728 3.2
mod3 Qatar June15 12 14 1.2 119 282 2.4000001 174 587 3.4000001 46 77 1.7 13 66 5.0999999 236 966 4.0999999 11 34 3.0999999 456 1225 2.7
mod3 Egypt June15 5 31 6.1999998 29 80 2.8 31 75 2.4000001 38 84 2.2 29 117 4 344 844 2.5 57 241 4.1999998 297 1216 4.0999999
mod3 Philippines June15 12 32 2.7 187 374 2 167 274 1.6 24 72 3 24 59 2.5 296 729 2.5 35 107 3.0999999 292 975 3.3
mod3 Serbia June15 8 20 2.5 32 172 5.4000001 7 11 1.6 80 145 1.8 28 56 2 532 898 1.7 63 175 2.8 135 411 3
mod3 Slowenia June15 76 85 1.1 55 243 4.4000001 92 126 1.4 43 83 1.9 43 95 2.2 315 586 1.9 90 218 2.4000001 63 200 3.2
mod3 Croatia June15 60 125 2.0999999 51 246 4.8000002 18 29 1.6 92 206 2.2 29 55 1.9 226 465 2.0999999 62 122 2 102 408 4
mod3 Liechtenstein June15 131 294 2.2 74 197 2.7 78 122 1.6 192 374 1.9 47 72 1.5 235 278 1.2 86 112 1.3 34 49 1.4
mod3 Chile June15 10 15 1.5 49 91 1.9 23 67 2.9000001 26 43 1.7 44 69 1.6 253 527 2.0999999 19 42 2.2 178 683 3.8
mod3 Estonia June15 50 55 1.1 193 395 2 176 387 2.2 26 42 1.6 25 38 1.5 158 274 1.7 69 121 1.8 111 285 2.5999999
mod3 Oman June15 7 20 2.9000001 61 123 2 207 460 2.2 11 25 2.3 2 4 2 342 623 1.8 0 0 0 101 433 4.3000002
mod3 Bahrain June15 5 24 4.8000002 6 61 10.2 78 237 3 3 9 3 0 0 0 73 227 3.0999999 6 31 5.1999998 162 562 3.5
mod3 Zyprus June15 28 52 1.9 53 90 1.7 10 34 3.4000001 20 42 2.0999999 7 16 2.3 95 199 2.0999999 76 150 2 71 198 2.8
mod3 Lathvia June15 25 37 1.5 84 242 2.9000001 45 126 2.8 54 84 1.6 6 14 2.3 217 389 1.8 26 62 2.4000001 87 238 2.7
mod3 Lituania June15 63 63 1 49 145 3 19 37 1.9 32 57 1.8 12 28 2.3 163 345 2.0999999 43 88 2 75 241 3.2
mod3 Belarus June15 25 81 3.2 64 111 1.7 38 221 5.8000002 22 44 2 6 6 1 68 190 2.8 14 31 2.2 81 253 3.0999999
mod3 Iceland June15 25 70 2.8 23 36 1.6 17 26 1.5 39 66 1.7 8 36 4.5 114 220 1.9 35 70 2 91 209 2.3
mod3 Malta June15 13 22 1.7 25 44 1.8 19 32 1.7 15 60 4 10 16 1.6 97 184 1.9 14 62 4.4000001 62 192 3.0999999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment