Upgrade to Pro — share decks privately, control downloads, hide ads and more …

data visualization @html5study

data visualization @html5study

muddydixon

March 28, 2023
Tweet

More Decks by muddydixon

Other Decks in Programming

Transcript

  1. σʔλՄࢹԽͱ͸ The main goal of data visualization is its ability

    to visualize data, communicating information clearly and effectivelty. Vitaly Friedman $ σʔλՄࢹԽͷ໨త͸ɺσʔλΛՄࢹԽ͠ɺ ৘ใΛ໌͔֬ͭޮ཰తʹ఻͑Δ͜ͱͰ͋Δ $
  2. σʔλՄࢹԽͱ͸ The main goal of data visualization is its ability

    to visualize data, communicating information clearly and effectivelty. Vitaly Friedman $ σʔλՄࢹԽͷ໨త͸ɺσʔλΛՄࢹԽ͠ɺ ৘ใΛ໌͔֬ͭޮ཰తʹ఻͑Δ͜ͱͰ͋Δ $
  3. ೝ஌ػೳɾܦݧΛϑϧʹ࢖͏  4FQBM-FOHU 4FQBM8JEU 1FUBM-FOHU 1FUBM8JEUI 4QFDJFT   

      TFUPTB      TFUPTB      TFUPTB      TFUPTB      TFUPTB      WFSTJDPMPS      WFSTJDPMPS      WFSTJDPMPS      WFSTJDPMPS      WFSTJDPMPS      WJSHJOJDB      WJSHJOJDB      WJSHJOJDB      WJSHJOJDB      WJSHJOJDB ΈΜͳ͍͖ͩ͢JSJT
  4. ౷ܭྔͰදݱ 4FQBM -FOHUI 4FQBM 8JEUI 1FUBM -FOHUI 1FUBM 8JEUI .JO

        TU 2V     .FEJBO     .FBO     SE 2V     .BY    
  5. ਤܗͷܦݧɾೝ஌ೳྗΛར༻ w ෼෍ͷ෯͕޿͍ w தԝ஋্͕ʹภ͍ͬͯΔ w େ͖ͭ͘ͷๆ͕͋Δ w தԝ஋͕एׯɺ্ ʹภΓ

    w ๆ͕ͭɾɾɾʁ w ۉ౳ʹ෼෍ w தԝ஋͕͓͓Α ͦத৺ w ଞͷଐੑͱൺֱͯ͠෼෍ ͷ෯͕খ͍͞ w ֎Ε஋͕ͪΒ΄Β
  6. ʮೝ஌ʯ͕ʮ೺ѲʯΛՃ଎ 4FQBM -FOHUI 4FQBM 8JEUI 1FUBM -FOHUI 1FUBM 8JEUI .JO

        TU 2V     .FEJBO     .FBO     SE 2V     .BY    
  7. σʔληοτͱՄࢹԽ  ΨΫย෯ Ֆห෯ 4QFDJFT    TFUPTB 

      TFUPTB    TFUPTB    TFUPTB    TFUPTB    WFSTJDPMPS    WFSTJDPMPS    WFSTJDPMPS    WFSTJDPMPS    WFSTJDPMPS    WJSHJOJDB    WJSHJOJDB    WJSHJOJDB    WJSHJOJDB    WJSHJOJDB
  8. ՄࢹԽͰҙࣝ͢Δ֓೦ σʔλ σʔλม਺ ࢹ֮ม਺ ࢹ֮ه߸ ՄࢹԽ σʔληοτ ༷ʑͳϑΟʔϧυͷ஋͔ΒͳΔ ϨίʔυΛෳ਺ؚΉσʔλ܈ ม਺நग़ɾ୅਺ॲཧɾ

    ई౓Խॲɾཧ౷ܭॲཧ͕ࡁΜͩ΋ͷ ՄࢹԽର৅ͱ͢ΔϑΟʔϧυΛ ؚΉσʔλɻͻͱͭͻͱ͕ͭҙຯΛ ࣋ͬͨ୯Ґ ྫɿ42-ͷߦ ϑΟʔϧυͷ஋ͦͷ΋ͷ ਺஋ ϝδϟʔ ΍ΧςΰϦม਺ σΟ ϝϯδϣϯ ɻͻͱͭͻͱ͕ͭࢹ֮ม ਺ʹஔ׵͞ΕΔ ࢹ֮දݱͻͱͭͻͱͭΛࢦ͢ Ґஔ΍αΠζɺ৭ɺ܏͖ɺڧ౓ ಁ໌ ౓ɾ࠼౓ɾ໌౓ ɺςΫενϟͳͲ ࢹ֮ม਺Λू໿ͤͨ͞ه߸ ఺΍ԁɺۣܗɺހɺཱମͳͲ σʔληοτͷσʔλʹରԠ͢Δ ه߸ͷू߹ʹΑΔՄࢹԽ ରԠ ରԠ ରԠ
  9. σʔληοτͱՄࢹԽ  ΨΫย෯ Ֆห෯ 4QFDJFT    TFUPTB 

      TFUPTB    TFUPTB    TFUPTB    TFUPTB    WFSTJDPMPS    WFSTJDPMPS    WFSTJDPMPS    WFSTJDPMPS    WFSTJDPMPS    WJSHJOJDB    WJSHJOJDB    WJSHJOJDB    WJSHJOJDB    WJSHJOJDB σʔλ ࢹ֮ه߸
  10. σʔληοτͱՄࢹԽ  ΨΫย෯ Ֆห෯ 4QFDJFT    TFUPTB 

      TFUPTB    TFUPTB    TFUPTB    TFUPTB    WFSTJDPMPS    WFSTJDPMPS    WFSTJDPMPS    WFSTJDPMPS    WFSTJDPMPS    WJSHJOJDB    WJSHJOJDB    WJSHJOJDB    WJSHJOJDB    WJSHJOJDB σʔλม਺ : ࢹ֮ม਺ 9 ৭
  11. ՄࢹԽͷ֓೦ ཧ۶্  4FQBM-FOHU I 4FQBM8JEUI 1FUBM-FOHUI 1FUBM8JEUI 4QFDJFT 

        TFUPTB      TFUPTB      TFUPTB      TFUPTB      TFUPTB      WFSTJDPMPS      WFSTJDPMPS      WFSTJDPMPS ᣾ย௕ Ֆห௕ छผ   TFUPTB ᣾ย௕  ൺྫई౓ Ֆห௕  ൺྫई౓ छผ TFUPTB ໊ٛई౓ ᣾ย௕ ൺྫई౓ Ґஔ Ֆห௕ ൺྫई౓ Ґஔ छผ ໊ٛई౓ ৭ 4FQBM-FOHUI 1FUBM-FOHUI 4QFDJFT   TFUPTB   TFUPTB   TFUPTB   TFUPTB   TFUPTB   WFSTJDPMPS   WFSTJDPMPS   WFSTJDPMPS ᣾ย௕ Ֆห௕ छผ   ੺ σʔληοτ σʔληοτ ม਺நग़ σʔλ σʔλม਺ ࢹ֮ม਺ ࢹ֮ه߸ ՄࢹԽ ରԠ ରԠ ରԠ
  12. 47(Ͱ࢖͑Δλά TWH H EFGT TZNCPM VTF QBUI MJOF SFDU DJSDMF

    FMMJQTF QPMZMJOF QPMZHPO ! ͋ͱ͸ϑΟϧλʔपΓ͕ͨ͘͞Μ͋Γ·͕͢ ΄ͱΜͲ࢖͏ػձ͸͋Γ·ͤΜ
  13. 47(͸͜Μͳײ͡ <svg width="400" height="300">! <g transform="translate(50,50)">! <circle r="5" cx="128.571" cy="111.733"

    fill="blue"></circle>! <circle r="5" cx="21.428" cy="121.600" fill="red"></circle>! <circle r="5" cx="77.142" cy="138.4" fill="blue"></circle>! <circle r="5" cx="111.428" cy="135.2" fill="blue"></circle>! <circle r="5" cx="300" cy="0" fill="red"></circle>! <circle r="5" cx="0" cy="73.066" fill="red"></circle>! <circle r="5" cx="244.285" cy="192.266" fill="blue"></circle>! <circle r="5" cx="270" cy="200" fill="red"></circle>! <circle r="5" cx="51.428" cy="173.333" fill="red"></circle>! </g>! </svg>
  14. %KTͱ͸ 63- IUUQEKTPSH  %BUB%SJWFO%PDVNFOUT EBUBʹج͍ͮͯIUNMTWHEPDVNFOU PCKFDUͷॲཧΛߦ͏ɺͱ͍͏ίϯηϓτ 47(ૢ࡞ ਺஋ॲཧ ՄࢹԽϢʔςΟϦςΟ

    ͷ૯߹+BWB4DSJQUϥΠϒϥϦ 47(TFMFDUPSBUUSTUZMF ਺஋ॲཧTDBMFOFTUBSSBZNBUI ՄࢹԽϢʔςΟϦςΟTDBMFBYJTMBZPVU
  15. ۩ମྫ <!doctype html>! <html lang="ja">! <head>! <meta charset="utf8">! <title>d3 introduction</title>!

    <style>! .axis line, .axis path { fill: none; stroke: grey; }! </style>! </head>! <body>! ! <div>! <p>0th paragraph</p>! <p>1st paragraph</p>! <p>2nd paragraph</p>! </div>! ! <script type="text/javascript" charset="utf8" src="../components/d3/d3.min.js"></script>! <script type="text/javascript" charset="utf8" src="./introduction.js"></script>! </body>! </html>
  16. ۩ମྫ ଐੑελΠϧૢ࡞ var paragraphs = d3.select('body').selectAll('p');! var pdata = [!

    {text: "modified: 0th paragraph"},! {text: "modified: 1th paragraph"},! {text: "modified: 2th paragraph"}! ];! paragraphs.data(pdata).text(function(d){ return d.text; }); EBUB ͰσʔλΛඥ෇͚Δ ͻͱͭͷQʹରͯ͠ɺͻͱͭͷ σʔλ  BUUS UFYU TUZMF ͳͲ͸Ҿ਺ʹඥ෇͚ΒΕͨσʔλΛ औΓɺͦΕʹԠͨ͡ॲཧΛߦ͏
  17. ۩ମྫ σʔλʹجͮ͘௥Ճ var pdata = d3.range(0, 5)! .map(function(id){! return {!

    id: id,! text: id + "th paragraph"! };! });! ! paragraphs.data(pdata).enter()! .append('p')! .text(function(d){! return d.text;! }); ૿͑ͨʂ
  18. var pdata = d3.range(0, 5)! .map(function(id){! return {! id: id,!

    text: id + "th paragraph"! };! });! ! paragraphs.data(pdata).enter()! .append('p')! .text(function(d){! return d.text;! }); ۩ମྫ σʔλʹجͮ͘௥Ճ FOUFS ʹΑͬͯɺσʔλ%0.Λॲཧͷର৅ʹ͢Δ
  19. ۩ମྫ σʔλʹجͮ͘࡟আ var lessData = pdata.slice(0, 2);! paragraphs.data(lessData).exit().remove(); ʮEBUB FYJU

    ʯ FYJU ʹΑͬͯɺ%0.σʔλΛॲཧͷର৅ʹ͢Δ σʔλ  ࠩ෼⾣͜Ε͕SFNPWF ͨ͠෼ طଘͷQ
  20. 4FMFDUJPO ྫ͑͹ ඥ෇͚ͨσʔλ طଘͷ%0. FYJU TFMFDUJPO FOUFS ଐੑɾελΠϧɾςΩ ετͷมߋͳͲΛߦ͏ ৽نʹ%0.Λ௥Ճ

    ͠ɺಉ࣌ʹଐੑɾελ ΠϧɾςΩετΛηο τ͢Δ طଘͷ%0.Λ࡟আ͠ ͨΓɺಁ໌౓Λ্͛ͨ ΓΛߦ͏
  21. <svg width="500" height="500">! <g width="480" height="480" transform="translate(10,10)">! <g class="background-layer">! <g

    class="ruler">! <line width="2" stroke="grey" fill="none" x1="0" x2="480" y1="0" y2="0"></line>! <line width="2" stroke="grey" fill="none" x1="0" x2="480" y1="48" y2="48"></line>! <line width="2" stroke="grey" fill="none" x1="0" x2="480" y1="96" y2="96"></line>! <line width="2" stroke="grey" fill="none" x1="0" x2="480" y1="144" y2="144"></line>! <line width="2" stroke="grey" fill="none" x1="0" x2="480" y1="192" y2="192"></line>! <line width="2" stroke="grey" fill="none" x1="0" x2="480" y1="240" y2="240"></line>! <line width="2" stroke="grey" fill="none" x1="0" x2="480" y1="288" y2="288"></line>! <line width="2" stroke="grey" fill="none" x1="0" x2="480" y1="336" y2="336"></line>! <line width="2" stroke="grey" fill="none" x1="0" x2="480" y1="384" y2="384"></line>! <line width="2" stroke="grey" fill="none" x1="0" x2="480" y1="432" y2="432"></line>! </g>! </g>! <g class="chart-layer">! <g><rect x="10" width="100" height="22" y="458" fill="#1f77b4"></rect></g>! <g><rect x="170" width="100" height="209" y="271" fill="#ff7f0e"></rect></g>! <g><rect x="330" width="100" height="478" y="2" fill="#2ca02c"></rect></g>! </g>! <g class="info-layer"></g>! </g>! </svg>
  22. σʔλՄࢹԽͱ͸ The main goal of data visualization is its ability

    to visualize data, communicating information clearly and effectivelty. Vitaly Friedman $ σʔλՄࢹԽͷ໨త͸ɺσʔλΛՄࢹԽ͠ɺ ৘ใΛ໌͔֬ͭޮ཰తʹ఻͑Δ͜ͱͰ͋Δ $
  23. σʔλՄࢹԽͷϚϯτϥ Overview First, Zoom and Filter, Then Details-on-Demand Overview First,

    Zoom and Filter, Then Details-on-Demand Overview First, Zoom and Filter, Then Details-on-Demand Ben Shneiderman $
  24. IUNM <!doctype html>! <html lang="ja">! <head>! <meta charset="utf8">! <title>d3 scatter

    plog</title>! <style>! .axis line, .axis path { fill: none; stroke: grey; }! </style>! </head>! <body>! <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>! <script type="text/javascript" charset="utf8" src="./iris.js"></script>! </body>! </html>
  25. +BWB4DSJQUσʔλͷಡΈࠐΈ var WIDTH = 500, HEIGHT = 500, margin =

    50;! var width = WIDTH - 2 * margin, height = HEIGHT - 2 * margin;! var key = 'Sepal.Length';! ! // iris.csv ϑΝΠϧΛಡΈࠐΉ! d3.csv(! "./iris.csv",! // ߦͷܕΛमਖ਼! function(d){! for(var attr in d){! if(! isNaN(Number(d[attr]))){! d[attr] = +d[attr];! }! return d;! }! },! // σʔλΛऔಘ! function(err, data){!
  26. +BWB4DSJQU47(ཁૉͷ࡞੒ // σʔλΛऔಘ! function(err, data){! ! // svgཁૉΛ௥Ճ! var svg

    = d3.select('body').append('svg').attr({! width: WIDTH,! height: HEIGHT! });! // ϚʔδϯΛ֬อͯ͠ɺ࣠ͳͲΛදࣔͰ͖ΔΑ͏ʹ͢Δ! var main = svg.append('g').attr({! width: width,! height: height,! transform: "translate("+margin+","+margin+")"! });! ! // ৭ͷई౓! var color = d3.scale.category10();
  27. +BWB4DSJQUσʔλͷ੔ܗͱ੔ཧ // σʔλΛೖΕࢠʹ͢Δ! var speciesData = d3.nest()! // छྨ͝ͱʹ෼ྨ͢ΔΩʔΛࢦఆ! .key(function(d){

    return d.Species;})! // ग़ྗΛΩʔʹϚονͨ͠഑ྻ͔Βɺฏۉ஋ʹมߋ! .rollup(function(values){! return d3.mean(values, function(d){ return d[key]; });! })! // ஋Λ഑ྻͰऔಘ! .entries(data);! ! // छྨͷΩʔҰཡΛऔಘ! var species = speciesData.map(function(d){ return d.key; });! ! // શମͷߴ͞ͷൣғΛऔಘ! var domain = d3.extent(data, function(d){ return d[key]; });!
  28. +BWB4DSJQUई౓࡞੒ // y࠲ඪͷई౓Λऔಘ! var yScale = d3.scale.linear()! // ม׵ޙͷൣғ(஋Ҭ)! .range([0,

    height])! // ม׵લͷൣғ(ఆٛҬ)! .domain([0, domain[1]]);! ! // x࠲ඪͷई౓Λऔಘ! var xScale = d3.scale.ordinal()! // ม׵ޙͷൣғ(஋Ҭ)! .rangeBands([0, width], .2)! // ม׵લͷൣғ(ఆٛҬ)! .domain(species);
  29. +BWB4DSJQU๮Λඳը // ๮(ͷάϧʔϓ)ཁૉΛ࡞੒! var bar = main.selectAll('g')! .data(speciesData)! .enter()! .append('g')!

    .attr({! transform: function(d){! return "translate("+xScale(d.key)+","+height+")";! }! });! ! // ๮Λඳը! bar.append('rect').attr({! // ۣܗͷߴ͞! height: function(d){ return yScale(d.values); },! // ۣܗͷҐஔ! y: function(d){ return -yScale(d.values); },! // ۣܗͷ෯! width: xScale.rangeBand(),! // ۣܗͷ৭! fill: function(d){ return color(d.key); }! });!
  30. +BWB4DSJQU๮ʹ஋Λඳը // ๮(ͷάϧʔϓ)ཁૉΛ࡞੒! var bar = main.selectAll('g')! .data(speciesData)! .enter()! .append('g')!

    .attr({! transform: function(d){! return "translate("+xScale(d.key)+","+height+")";! }! });! ! // ๮Λඳը (લड़)! // ஋Λඳը! bar.append('text')! // ςΩετ͸෼ྨͨ࣌͠ͷΩʔ! .text(function(d){! return d.values.toFixed(2);! })! .attr({! // ҐஔΛ๮ͷ্ʹ! dy: function(d){ return - yScale(d.values); },! dx: xScale.rangeBand() / 2,! fill: 'black'! }).style('text-anchor', 'middle');
  31. +BWB4DSJQU࣠ͷඳը // x࣠ੜ੒ͷϢʔςΟϦςΟ! var xAxisSvg = d3.svg.axis().scale(xScale);! // y࣠ੜ੒ͷϢʔςΟϦςΟ! var

    yAxisSvg = d3.svg.axis().scale(yScale.copy()! .range([height, 0])).orient('left');! // x࣠Λੜ੒! var xAxis = main.append('g').call(xAxisSvg).attr('class', 'axis')! .attr("transform", "translate(0,"+height+")");! // y࣠Λੜ੒! var yAxis = main.append('g').call(yAxisSvg).attr('class', 'axis');! ! // y࣠ͷϥϕϧΛهड़! main.append('text').text(key).attr({! transform: "translate(-30,"+(height / 2)+") rotate(-90)"! });