Search code examples
plotchartswolfram-mathematica

How to create chart of decomposition data to categories?


I looking for programs or libraries that allow to create graphics presented below:

Idea is the following:

  • W have some initial value
  • It is divided to different states
  • These divisions can occur some times
  • We want to present name and value connected with each state

Is is possible to generate such image in Wolfram Mathematica? If yes which functions should I use.

enter image description here

Graph presented on this image shows history of usage Tinder application.

Source:

https://www.reddit.com/r/dataisbeautiful/comments/83ttdq/oc_my_28_days_on_tinder/


Solution

  • I decided to no use Mathematica but create this graph in JavaScript.

    https://www.amcharts.com/docs/v4/chart-types/sankey-diagram/

    /**
     * ---------------------------------------
     * This demo was created using amCharts 4.
     *
     * For more information visit:
     * https://www.amcharts.com/
     *
     * Documentation is available at:
     * https://www.amcharts.com/docs/v4/
     * ---------------------------------------
     */
    
    // Create chart instance
    var chart = am4core.create("chartdiv", am4charts.SankeyDiagram);
    
    chart.data = [
      { "from": "A", "to": "D", "value": 10 },
      { "from": "B", "to": "D", "value": 8 },
      { "from": "B", "to": "E", "value": 4 },
      { "from": "C", "to": "E", "value": 3 },
      { "from": "D", "to": "G", "value": 5 },
      { "from": "D", "to": "I", "value": 2 },
      { "from": "D", "to": "H", "value": 3 },
      { "from": "E", "to": "H", "value": 6 },
      { "from": "G", "to": "J", "value": 5 },
      { "from": "I", "to": "J", "value": 1 },
      { "from": "H", "to": "J", "value": 9 }
    ];
    
    chart.dataFields.fromName = "from";
    chart.dataFields.toName = "to";
    chart.dataFields.value = "value";
    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    }
    
    #chartdiv {
      width: 100%;
      height: 300px;
    }
    <script src="//www.amcharts.com/lib/4/core.js"></script>
    <script src="//www.amcharts.com/lib/4/charts.js"></script>
    <script src="//www.amcharts.com/lib/4/themes/animated.js"></script>
    <div id="chartdiv"></div>