{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "Install the spreadsheet gem version ~>1.1.1 for using spreadsheet functions.\n",
      "\n",
      "Install the mechanize gem version ~>2.7.5 for using mechanize functions.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "require 'daru/view'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "if(window['d3'] === undefined ||\n",
       "   window['Nyaplot'] === undefined){\n",
       "    var path = {\"d3\":\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min\",\"downloadable\":\"http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable\"};\n",
       "\n",
       "\n",
       "\n",
       "    var shim = {\"d3\":{\"exports\":\"d3\"},\"downloadable\":{\"exports\":\"downloadable\"}};\n",
       "\n",
       "    require.config({paths: path, shim:shim});\n",
       "\n",
       "\n",
       "require(['d3'], function(d3){window['d3']=d3;console.log('finished loading d3');require(['downloadable'], function(downloadable){window['downloadable']=downloadable;console.log('finished loading downloadable');\n",
       "\n",
       "\tvar script = d3.select(\"head\")\n",
       "\t    .append(\"script\")\n",
       "\t    .attr(\"src\", \"http://cdn.rawgit.com/domitry/Nyaplotjs/master/release/nyaplot.js\")\n",
       "\t    .attr(\"async\", true);\n",
       "\n",
       "\tscript[0][0].onload = script[0][0].onreadystatechange = function(){\n",
       "\n",
       "\n",
       "\t    var event = document.createEvent(\"HTMLEvents\");\n",
       "\t    event.initEvent(\"load_nyaplot\",false,false);\n",
       "\t    window.dispatchEvent(event);\n",
       "\t    console.log('Finished loading Nyaplotjs');\n",
       "\n",
       "\t};\n",
       "\n",
       "\n",
       "});});\n",
       "}\n"
      ],
      "text/plain": [
       "\"if(window['d3'] === undefined ||\\n   window['Nyaplot'] === undefined){\\n    var path = {\\\"d3\\\":\\\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min\\\",\\\"downloadable\\\":\\\"http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable\\\"};\\n\\n\\n\\n    var shim = {\\\"d3\\\":{\\\"exports\\\":\\\"d3\\\"},\\\"downloadable\\\":{\\\"exports\\\":\\\"downloadable\\\"}};\\n\\n    require.config({paths: path, shim:shim});\\n\\n\\nrequire(['d3'], function(d3){window['d3']=d3;console.log('finished loading d3');require(['downloadable'], function(downloadable){window['downloadable']=downloadable;console.log('finished loading downloadable');\\n\\n\\tvar script = d3.select(\\\"head\\\")\\n\\t    .append(\\\"script\\\")\\n\\t    .attr(\\\"src\\\", \\\"http://cdn.rawgit.com/domitry/Nyaplotjs/master/release/nyaplot.js\\\")\\n\\t    .attr(\\\"async\\\", true);\\n\\n\\tscript[0][0].onload = script[0][0].onreadystatechange = function(){\\n\\n\\n\\t    var event = document.createEvent(\\\"HTMLEvents\\\");\\n\\t    event.initEvent(\\\"load_nyaplot\\\",false,false);\\n\\t    window.dispatchEvent(event);\\n\\t    console.log('Finished loading Nyaplotjs');\\n\\n\\t};\\n\\n\\n});});\\n}\\n\""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       ":nyaplot"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Daru::View.plotting_library = :nyaplot"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Categorical Vector Visualization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "  <tr>\n",
       "    <th colspan=\"2\">Daru::Vector(6):category</th>\n",
       "  </tr>\n",
       "  \n",
       "\n",
       "  \n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>a</td>\n",
       "    </tr>\n",
       "  \n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>a</td>\n",
       "    </tr>\n",
       "  \n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>a</td>\n",
       "    </tr>\n",
       "  \n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>b</td>\n",
       "    </tr>\n",
       "  \n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>b</td>\n",
       "    </tr>\n",
       "  \n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>c</td>\n",
       "    </tr>\n",
       "  \n",
       "\n",
       "  \n",
       "</table>"
      ],
      "text/plain": [
       "#<Daru::Vector(6):cataegory>\n",
       "   0   a\n",
       "   1   a\n",
       "   2   a\n",
       "   3   b\n",
       "   4   b\n",
       "   5   c"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dv = Daru::Vector.new [:a, :a, :a, :b, :b, :c], type: :category"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Bar graph\n",
    "\n",
    "##### 1. Frequency (count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#<Daru::View::Plot:0x007fd05c935a10 @data=#<Daru::Vector(6):cataegory>\n",
       "   0   a\n",
       "   1   a\n",
       "   2   a\n",
       "   3   b\n",
       "   4   b\n",
       "   5   c, @options={:type=>:bar, :method=>:count}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x007fd05c935830 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05c92cc80 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"da25c1e7-7aad-4496-954d-2b4ebd49b531\"}, @xrange=[:a, :b, :c], @yrange=[0, 3]>], :options=>{}}>>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar_graph1 = Daru::View::Plot.new(dv, type: :bar)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Nyaplot::Plot"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar_graph1.chart.class"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-a9909bc7-df51-4925-af63-73de4372f3be'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"da25c1e7-7aad-4496-954d-2b4ebd49b531\"}],\"options\":{\"width\":700,\"xrange\":[\"a\",\"b\",\"c\"],\"yrange\":[0,3]}}],\"data\":{\"da25c1e7-7aad-4496-954d-2b4ebd49b531\":[{\"data0\":\"a\",\"data1\":3},{\"data0\":\"b\",\"data1\":2},{\"data0\":\"c\",\"data1\":1}]},\"extension\":[]}\n",
       "        var id_name = '#vis-a9909bc7-df51-4925-af63-73de4372f3be';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Frame:0x007fd05c85e6f0 @properties={:panes=>[#<Nyaplot::Plot:0x007fd05c935830 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05c92cc80 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"da25c1e7-7aad-4496-954d-2b4ebd49b531\"}, @xrange=[:a, :b, :c], @yrange=[0, 3]>], :options=>{:width=>700, :xrange=>[:a, :b, :c], :yrange=>[0, 3]}}>], :data=>{\"da25c1e7-7aad-4496-954d-2b4ebd49b531\"=>#<Nyaplot::DataFrame:0x007fd05c92e828 @name=\"da25c1e7-7aad-4496-954d-2b4ebd49b531\", @rows=[{:data0=>:a, :data1=>3}, {:data0=>:b, :data1=>2}, {:data0=>:c, :data1=>1}]>}, :extension=>[]}>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "bar_graph1.show_in_iruby"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       ":category"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dv = Daru::Vector.new ['III']*10 + ['II']*5 + ['I']*5, type: :category, categories: ['I', 'II', 'III']\n",
    "dv.type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#<Daru::View::Plot:0x007fd05b2faf20 @data=#<Daru::Vector(20):cataegory>\n",
       "   0 III\n",
       "   1 III\n",
       "   2 III\n",
       "   3 III\n",
       "   4 III\n",
       "   5 III\n",
       "   6 III\n",
       "   7 III\n",
       "   8 III\n",
       "   9 III\n",
       "  10  II\n",
       "  11  II\n",
       "  12  II\n",
       "  13  II\n",
       "  14  II\n",
       " ... ..., @options={:type=>:bar, :method=>:count}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x007fd05b2fae30 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05b2f90d0 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"9e71388d-9a02-42cd-adcc-fd532045edf3\"}, @xrange=[\"I\", \"II\", \"III\"], @yrange=[0, 10]>], :options=>{}}>>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar_graph2 = Daru::View::Plot.new(dv, type: :bar)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Daru::View::Plot"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar_graph2.class"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Nyaplot::Plot"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar_graph2.chart.class"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-06549f53-653c-4dc4-a7fe-d0ceb3a80658'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"9e71388d-9a02-42cd-adcc-fd532045edf3\"}],\"options\":{\"x_label\":\"Cat\",\"y_label\":\"Frequency\",\"width\":700,\"xrange\":[\"I\",\"II\",\"III\"],\"yrange\":[0,10]}}],\"data\":{\"9e71388d-9a02-42cd-adcc-fd532045edf3\":[{\"data0\":\"I\",\"data1\":5},{\"data0\":\"II\",\"data1\":5},{\"data0\":\"III\",\"data1\":10}]},\"extension\":[]}\n",
       "        var id_name = '#vis-06549f53-653c-4dc4-a7fe-d0ceb3a80658';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Plot:0x007fd05b2fae30 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05b2f90d0 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"9e71388d-9a02-42cd-adcc-fd532045edf3\"}, @xrange=[\"I\", \"II\", \"III\"], @yrange=[0, 10]>], :options=>{:x_label=>\"Cat\", :y_label=>\"Frequency\", :width=>700, :xrange=>[\"I\", \"II\", \"III\"], :yrange=>[0, 10]}}>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Nyaplot methods will work.Since #chart is Nyaplot::Plot class object\n",
    "bar_graph2.chart.x_label 'Cat'\n",
    "bar_graph2.chart.y_label 'Frequency'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-39949ceb-290a-46cb-bc6f-4a7c37f15ed5'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"9e71388d-9a02-42cd-adcc-fd532045edf3\"}],\"options\":{\"x_label\":\"Cat\",\"y_label\":\"Frequency\",\"width\":700,\"xrange\":[\"I\",\"II\",\"III\"],\"yrange\":[0,10]}}],\"data\":{\"9e71388d-9a02-42cd-adcc-fd532045edf3\":[{\"data0\":\"I\",\"data1\":5},{\"data0\":\"II\",\"data1\":5},{\"data0\":\"III\",\"data1\":10}]},\"extension\":[]}\n",
       "        var id_name = '#vis-39949ceb-290a-46cb-bc6f-4a7c37f15ed5';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Plot:0x007fd05b2fae30 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05b2f90d0 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"9e71388d-9a02-42cd-adcc-fd532045edf3\"}, @xrange=[\"I\", \"II\", \"III\"], @yrange=[0, 10]>], :options=>{:x_label=>\"Cat\", :y_label=>\"Frequency\", :width=>700, :xrange=>[\"I\", \"II\", \"III\"], :yrange=>[0, 10]}}>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar_graph2.chart # or bar_graph2.show_in_iruby"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2. Percentage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#<Daru::View::Plot:0x007fd05c34a678 @data=#<Daru::Vector(20):cataegory>\n",
       "   0 III\n",
       "   1 III\n",
       "   2 III\n",
       "   3 III\n",
       "   4 III\n",
       "   5 III\n",
       "   6 III\n",
       "   7 III\n",
       "   8 III\n",
       "   9 III\n",
       "  10  II\n",
       "  11  II\n",
       "  12  II\n",
       "  13  II\n",
       "  14  II\n",
       " ... ..., @options={:type=>:bar, :method=>:percentage}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x007fd05c34be10 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05b29a030 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"decb6897-b99b-420e-861d-bbe7a8375714\"}, @xrange=[\"I\", \"II\", \"III\"], @yrange=[0, 50.0]>], :options=>{:yrange=>[0, 100]}}>>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar_graph2_per = Daru::View::Plot.new(dv, type: :bar, method: :percentage)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-d7b0494c-0239-442a-ac66-30ab74e04196'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"decb6897-b99b-420e-861d-bbe7a8375714\"}],\"options\":{\"yrange\":[0,100],\"x_label\":\"Categories\",\"y_label\":\"Percentage (%)\",\"width\":700,\"xrange\":[\"I\",\"II\",\"III\"]}}],\"data\":{\"decb6897-b99b-420e-861d-bbe7a8375714\":[{\"data0\":\"I\",\"data1\":25.0},{\"data0\":\"II\",\"data1\":25.0},{\"data0\":\"III\",\"data1\":50.0}]},\"extension\":[]}\n",
       "        var id_name = '#vis-d7b0494c-0239-442a-ac66-30ab74e04196';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Frame:0x007fd05bb58eb0 @properties={:panes=>[#<Nyaplot::Plot:0x007fd05c34be10 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05b29a030 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"decb6897-b99b-420e-861d-bbe7a8375714\"}, @xrange=[\"I\", \"II\", \"III\"], @yrange=[0, 50.0]>], :options=>{:yrange=>[0, 100], :x_label=>\"Categories\", :y_label=>\"Percentage (%)\", :width=>700, :xrange=>[\"I\", \"II\", \"III\"]}}>], :data=>{\"decb6897-b99b-420e-861d-bbe7a8375714\"=>#<Nyaplot::DataFrame:0x007fd05b29ab70 @name=\"decb6897-b99b-420e-861d-bbe7a8375714\", @rows=[{:data0=>\"I\", :data1=>25.0}, {:data0=>\"II\", :data1=>25.0}, {:data0=>\"III\", :data1=>50.0}]>}, :extension=>[]}>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "bar_graph2_per.chart.x_label 'Categories'\n",
    "bar_graph2_per.chart.y_label 'Percentage (%)'\n",
    "bar_graph2_per.show_in_iruby"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3. Fraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#<Daru::View::Plot:0x007fd05ca92c28 @data=#<Daru::Vector(20):cataegory>\n",
       "   0 III\n",
       "   1 III\n",
       "   2 III\n",
       "   3 III\n",
       "   4 III\n",
       "   5 III\n",
       "   6 III\n",
       "   7 III\n",
       "   8 III\n",
       "   9 III\n",
       "  10  II\n",
       "  11  II\n",
       "  12  II\n",
       "  13  II\n",
       "  14  II\n",
       " ... ..., @options={:type=>:bar, :method=>:fraction}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x007fd05ca92bb0 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05ca91850 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"017196d6-46a0-47c8-a234-bb2c67fa8c0c\"}, @xrange=[\"I\", \"II\", \"III\"], @yrange=[0, 0.5]>], :options=>{:yrange=>[0, 1]}}>>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar_graph2_frac = Daru::View::Plot.new(dv, type: :bar, method: :fraction)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-24075e1a-c2c6-418c-a960-1226d92ee0b2'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"017196d6-46a0-47c8-a234-bb2c67fa8c0c\"}],\"options\":{\"yrange\":[0,1],\"y_label\":\"Fraction\",\"width\":700,\"xrange\":[\"I\",\"II\",\"III\"]}}],\"data\":{\"017196d6-46a0-47c8-a234-bb2c67fa8c0c\":[{\"data0\":\"I\",\"data1\":0.25},{\"data0\":\"II\",\"data1\":0.25},{\"data0\":\"III\",\"data1\":0.5}]},\"extension\":[]}\n",
       "        var id_name = '#vis-24075e1a-c2c6-418c-a960-1226d92ee0b2';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Frame:0x007fd05ca42d68 @properties={:panes=>[#<Nyaplot::Plot:0x007fd05ca92bb0 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05ca91850 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"017196d6-46a0-47c8-a234-bb2c67fa8c0c\"}, @xrange=[\"I\", \"II\", \"III\"], @yrange=[0, 0.5]>], :options=>{:yrange=>[0, 1], :y_label=>\"Fraction\", :width=>700, :xrange=>[\"I\", \"II\", \"III\"]}}>], :data=>{\"017196d6-46a0-47c8-a234-bb2c67fa8c0c\"=>#<Nyaplot::DataFrame:0x007fd05ca91f30 @name=\"017196d6-46a0-47c8-a234-bb2c67fa8c0c\", @rows=[{:data0=>\"I\", :data1=>0.25}, {:data0=>\"II\", :data1=>0.25}, {:data0=>\"III\", :data1=>0.5}]>}, :extension=>[]}>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# bar_graph2_frac.chart.x_label 'Categories'\n",
    "bar_graph2_frac.chart.y_label 'Fraction'\n",
    "bar_graph2_frac.show_in_iruby"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Categorical data visualization in Dataframe\n",
    "### Bar Graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       ":category"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = Daru::DataFrame.new({\n",
    "  a: [1, 2, 4, -2, 5, 23, 0],\n",
    "  b: [3, 1, 3, -6, 2, 1, 0],\n",
    "  c: ['I', 'II', 'I', 'III', 'I', 'III', 'II']\n",
    "  })\n",
    "df.to_category :c\n",
    "df[:c].type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#<Daru::View::Plot:0x007fd05bb12140 @data=#<Daru::DataFrame(7x3)>\n",
       "       a   b   c\n",
       "   0   1   3   I\n",
       "   1   2   1  II\n",
       "   2   4   3   I\n",
       "   3  -2  -6 III\n",
       "   4   5   2   I\n",
       "   5  23   1 III\n",
       "   6   0   0  II, @options={:type=>:bar, :x=>:c}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x007fd05bb12028 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05bb01cc8 @properties={:type=>:bar, :options=>{:value=>:c}, :data=>\"dc767bc5-1edb-4065-a450-a9a3f4241eac\"}, @xrange=[\"I\", \"II\", \"III\"], @yrange=[0, 7]>], :options=>{}}>>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar_graph3 = Daru::View::Plot.new(df, type: :bar, x: :c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-703fc484-9142-435a-845d-9b86f5ed0622'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"value\":\"c\"},\"data\":\"dc767bc5-1edb-4065-a450-a9a3f4241eac\"}],\"options\":{\"width\":700,\"xrange\":[\"I\",\"II\",\"III\"],\"yrange\":[0,7]}}],\"data\":{\"dc767bc5-1edb-4065-a450-a9a3f4241eac\":[{\"a\":1,\"b\":3,\"c\":\"I\"},{\"a\":2,\"b\":1,\"c\":\"II\"},{\"a\":4,\"b\":3,\"c\":\"I\"},{\"a\":-2,\"b\":-6,\"c\":\"III\"},{\"a\":5,\"b\":2,\"c\":\"I\"},{\"a\":23,\"b\":1,\"c\":\"III\"},{\"a\":0,\"b\":0,\"c\":\"II\"}]},\"extension\":[]}\n",
       "        var id_name = '#vis-703fc484-9142-435a-845d-9b86f5ed0622';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Frame:0x007fd05c2cace8 @properties={:panes=>[#<Nyaplot::Plot:0x007fd05bb12028 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05bb01cc8 @properties={:type=>:bar, :options=>{:value=>:c}, :data=>\"dc767bc5-1edb-4065-a450-a9a3f4241eac\"}, @xrange=[\"I\", \"II\", \"III\"], @yrange=[0, 7]>], :options=>{:width=>700, :xrange=>[\"I\", \"II\", \"III\"], :yrange=>[0, 7]}}>], :data=>{\"dc767bc5-1edb-4065-a450-a9a3f4241eac\"=>#<Nyaplot::DataFrame:0x007fd05bb022b8 @name=\"dc767bc5-1edb-4065-a450-a9a3f4241eac\", @rows=[{:a=>1, :b=>3, :c=>\"I\"}, {:a=>2, :b=>1, :c=>\"II\"}, {:a=>4, :b=>3, :c=>\"I\"}, {:a=>-2, :b=>-6, :c=>\"III\"}, {:a=>5, :b=>2, :c=>\"I\"}, {:a=>23, :b=>1, :c=>\"III\"}, {:a=>0, :b=>0, :c=>\"II\"}]>}, :extension=>[]}>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "bar_graph3.show_in_iruby"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Scatter plot categorized by categorical variable¶\n",
    "#### Plots can be categorized by\n",
    "\n",
    "- Color\n",
    "- Size\n",
    "- Shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       ":category"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = Daru::DataFrame.new({\n",
    "  a: [1, 2, 4, -2, 5, 23, 0],\n",
    "  b: [3, 1, 3, -6, 2, 1, 0],\n",
    "  c: ['I', 'II', 'I', 'III', 'I', 'III', 'II']\n",
    "  })\n",
    "df.to_category :c\n",
    "df[:c].type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#<Daru::View::Plot:0x007fd05bac9af8 @data=#<Daru::DataFrame(7x3)>\n",
       "       a   b   c\n",
       "   0   1   3   I\n",
       "   1   2   1  II\n",
       "   2   4   3   I\n",
       "   3  -2  -6 III\n",
       "   4   5   2   I\n",
       "   5  23   1 III\n",
       "   6   0   0  II, @options={:type=>:scatter, :x=>:a, :y=>:b, :categorized=>{:by=>:c, :method=>:color}}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x007fd05bac9a80 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05bac3720 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"I\", :color=>\"rgb(102,194,165)\", :tooltip_contents=>[\"I\", \"I\", \"I\"]}, :data=>\"65223cdc-8436-4095-bdc5-b7fa8f573b07\"}, @xrange=[1, 5], @yrange=[2, 3]>, #<Nyaplot::Diagram:0x007fd05b24a198 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"II\", :color=>\"rgb(252,141,98)\", :tooltip_contents=>[\"II\", \"II\"]}, :data=>\"b0f52746-cec0-4ef7-8a5b-10e1ea06e36f\"}, @xrange=[0, 2], @yrange=[0, 1]>, #<Nyaplot::Diagram:0x007fd05c24ba10 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"III\", :color=>\"rgb(141,160,203)\", :tooltip_contents=>[\"III\", \"III\"]}, :data=>\"e394ca43-e59f-4965-b25d-c42721aab2bf\"}, @xrange=[-2, 23], @yrange=[-6, 1]>], :options=>{:legend=>true}}>>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scatter_1 = Daru::View::Plot.new(df, type: :scatter, x: :a, y: :b, categorized: {by: :c, method: :color})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-fdaf3017-dba7-481a-8e9e-4b18ef0f7d74'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"I\",\"color\":\"rgb(102,194,165)\",\"tooltip_contents\":[\"I\",\"I\",\"I\"]},\"data\":\"65223cdc-8436-4095-bdc5-b7fa8f573b07\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"II\",\"color\":\"rgb(252,141,98)\",\"tooltip_contents\":[\"II\",\"II\"]},\"data\":\"b0f52746-cec0-4ef7-8a5b-10e1ea06e36f\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"III\",\"color\":\"rgb(141,160,203)\",\"tooltip_contents\":[\"III\",\"III\"]},\"data\":\"e394ca43-e59f-4965-b25d-c42721aab2bf\"}],\"options\":{\"legend\":true,\"zoom\":true,\"width\":800,\"xrange\":[-2,23],\"yrange\":[-6,3]}}],\"data\":{\"65223cdc-8436-4095-bdc5-b7fa8f573b07\":[{\"a\":1,\"b\":3},{\"a\":4,\"b\":3},{\"a\":5,\"b\":2}],\"b0f52746-cec0-4ef7-8a5b-10e1ea06e36f\":[{\"a\":2,\"b\":1},{\"a\":0,\"b\":0}],\"e394ca43-e59f-4965-b25d-c42721aab2bf\":[{\"a\":-2,\"b\":-6},{\"a\":23,\"b\":1}]},\"extension\":[]}\n",
       "        var id_name = '#vis-fdaf3017-dba7-481a-8e9e-4b18ef0f7d74';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Frame:0x007fd05b2291f0 @properties={:panes=>[#<Nyaplot::Plot:0x007fd05bac9a80 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05bac3720 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"I\", :color=>\"rgb(102,194,165)\", :tooltip_contents=>[\"I\", \"I\", \"I\"]}, :data=>\"65223cdc-8436-4095-bdc5-b7fa8f573b07\"}, @xrange=[1, 5], @yrange=[2, 3]>, #<Nyaplot::Diagram:0x007fd05b24a198 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"II\", :color=>\"rgb(252,141,98)\", :tooltip_contents=>[\"II\", \"II\"]}, :data=>\"b0f52746-cec0-4ef7-8a5b-10e1ea06e36f\"}, @xrange=[0, 2], @yrange=[0, 1]>, #<Nyaplot::Diagram:0x007fd05c24ba10 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"III\", :color=>\"rgb(141,160,203)\", :tooltip_contents=>[\"III\", \"III\"]}, :data=>\"e394ca43-e59f-4965-b25d-c42721aab2bf\"}, @xrange=[-2, 23], @yrange=[-6, 1]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[-2, 23], :yrange=>[-6, 3]}}>], :data=>{\"65223cdc-8436-4095-bdc5-b7fa8f573b07\"=>#<Nyaplot::DataFrame:0x007fd05bac3b80 @name=\"65223cdc-8436-4095-bdc5-b7fa8f573b07\", @rows=[{:a=>1, :b=>3}, {:a=>4, :b=>3}, {:a=>5, :b=>2}]>, \"b0f52746-cec0-4ef7-8a5b-10e1ea06e36f\"=>#<Nyaplot::DataFrame:0x007fd05b24a580 @name=\"b0f52746-cec0-4ef7-8a5b-10e1ea06e36f\", @rows=[{:a=>2, :b=>1}, {:a=>0, :b=>0}]>, \"e394ca43-e59f-4965-b25d-c42721aab2bf\"=>#<Nyaplot::DataFrame:0x007fd05c24bd80 @name=\"e394ca43-e59f-4965-b25d-c42721aab2bf\", @rows=[{:a=>-2, :b=>-6}, {:a=>23, :b=>1}]>}, :extension=>[]}>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "scatter_1.show_in_iruby"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-d8fdb108-862a-4e6e-bb6a-6a17a6f07ad9'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"I\",\"color\":\"rgb(102,194,165)\",\"tooltip_contents\":[\"I\",\"I\",\"I\"]},\"data\":\"65223cdc-8436-4095-bdc5-b7fa8f573b07\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"II\",\"color\":\"rgb(252,141,98)\",\"tooltip_contents\":[\"II\",\"II\"]},\"data\":\"b0f52746-cec0-4ef7-8a5b-10e1ea06e36f\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"III\",\"color\":\"rgb(141,160,203)\",\"tooltip_contents\":[\"III\",\"III\"]},\"data\":\"e394ca43-e59f-4965-b25d-c42721aab2bf\"}],\"options\":{\"legend\":true,\"zoom\":true,\"width\":800,\"xrange\":[-10,10],\"yrange\":[-10,10]}}],\"data\":{\"65223cdc-8436-4095-bdc5-b7fa8f573b07\":[{\"a\":1,\"b\":3},{\"a\":4,\"b\":3},{\"a\":5,\"b\":2}],\"b0f52746-cec0-4ef7-8a5b-10e1ea06e36f\":[{\"a\":2,\"b\":1},{\"a\":0,\"b\":0}],\"e394ca43-e59f-4965-b25d-c42721aab2bf\":[{\"a\":-2,\"b\":-6},{\"a\":23,\"b\":1}]},\"extension\":[]}\n",
       "        var id_name = '#vis-d8fdb108-862a-4e6e-bb6a-6a17a6f07ad9';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Plot:0x007fd05bac9a80 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05bac3720 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"I\", :color=>\"rgb(102,194,165)\", :tooltip_contents=>[\"I\", \"I\", \"I\"]}, :data=>\"65223cdc-8436-4095-bdc5-b7fa8f573b07\"}, @xrange=[1, 5], @yrange=[2, 3]>, #<Nyaplot::Diagram:0x007fd05b24a198 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"II\", :color=>\"rgb(252,141,98)\", :tooltip_contents=>[\"II\", \"II\"]}, :data=>\"b0f52746-cec0-4ef7-8a5b-10e1ea06e36f\"}, @xrange=[0, 2], @yrange=[0, 1]>, #<Nyaplot::Diagram:0x007fd05c24ba10 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"III\", :color=>\"rgb(141,160,203)\", :tooltip_contents=>[\"III\", \"III\"]}, :data=>\"e394ca43-e59f-4965-b25d-c42721aab2bf\"}, @xrange=[-2, 23], @yrange=[-6, 1]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[-10, 10], :yrange=>[-10, 10]}}>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scatter_1.chart.xrange [-10, 10]\n",
    "scatter_1.chart.yrange [-10, 10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-8a4277f1-830d-46bd-aa71-dd55b4385772'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"I\",\"shape\":\"circle\",\"tooltip_contents\":[\"I\",\"I\",\"I\"]},\"data\":\"827961c8-07b6-4e43-92e4-ad118cacac4d\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"II\",\"shape\":\"triangle-up\",\"tooltip_contents\":[\"II\",\"II\"]},\"data\":\"f05f2c4a-627e-44df-8b35-985718e0dde8\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"III\",\"shape\":\"diamond\",\"tooltip_contents\":[\"III\",\"III\"]},\"data\":\"3f90c3cf-18f4-4789-9ddd-c2dbbac066c9\"}],\"options\":{\"legend\":true,\"zoom\":true,\"width\":800,\"xrange\":[-2,23],\"yrange\":[-6,3]}}],\"data\":{\"827961c8-07b6-4e43-92e4-ad118cacac4d\":[{\"a\":1,\"b\":3},{\"a\":4,\"b\":3},{\"a\":5,\"b\":2}],\"f05f2c4a-627e-44df-8b35-985718e0dde8\":[{\"a\":2,\"b\":1},{\"a\":0,\"b\":0}],\"3f90c3cf-18f4-4789-9ddd-c2dbbac066c9\":[{\"a\":-2,\"b\":-6},{\"a\":23,\"b\":1}]},\"extension\":[]}\n",
       "        var id_name = '#vis-8a4277f1-830d-46bd-aa71-dd55b4385772';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Frame:0x007fd05c1d0ef0 @properties={:panes=>[#<Nyaplot::Plot:0x007fd05c1db378 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05c9a8bc8 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"I\", :shape=>\"circle\", :tooltip_contents=>[\"I\", \"I\", \"I\"]}, :data=>\"827961c8-07b6-4e43-92e4-ad118cacac4d\"}, @xrange=[1, 5], @yrange=[2, 3]>, #<Nyaplot::Diagram:0x007fd05baabfa8 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"II\", :shape=>\"triangle-up\", :tooltip_contents=>[\"II\", \"II\"]}, :data=>\"f05f2c4a-627e-44df-8b35-985718e0dde8\"}, @xrange=[0, 2], @yrange=[0, 1]>, #<Nyaplot::Diagram:0x007fd05c1d2098 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"III\", :shape=>\"diamond\", :tooltip_contents=>[\"III\", \"III\"]}, :data=>\"3f90c3cf-18f4-4789-9ddd-c2dbbac066c9\"}, @xrange=[-2, 23], @yrange=[-6, 1]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[-2, 23], :yrange=>[-6, 3]}}>], :data=>{\"827961c8-07b6-4e43-92e4-ad118cacac4d\"=>#<Nyaplot::DataFrame:0x007fd05c9a8fd8 @name=\"827961c8-07b6-4e43-92e4-ad118cacac4d\", @rows=[{:a=>1, :b=>3}, {:a=>4, :b=>3}, {:a=>5, :b=>2}]>, \"f05f2c4a-627e-44df-8b35-985718e0dde8\"=>#<Nyaplot::DataFrame:0x007fd05b208270 @name=\"f05f2c4a-627e-44df-8b35-985718e0dde8\", @rows=[{:a=>2, :b=>1}, {:a=>0, :b=>0}]>, \"3f90c3cf-18f4-4789-9ddd-c2dbbac066c9\"=>#<Nyaplot::DataFrame:0x007fd05c1d2408 @name=\"3f90c3cf-18f4-4789-9ddd-c2dbbac066c9\", @rows=[{:a=>-2, :b=>-6}, {:a=>23, :b=>1}]>}, :extension=>[]}>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "scatter_2 = Daru::View::Plot.new(df, type: :scatter, x: :a, y: :b, categorized: {by: :c, method: :shape})\n",
    "scatter_2.show_in_iruby"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-c959743a-7a5f-472a-9399-2eb8bb4b0978'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"I\",\"shape\":\"circle\",\"tooltip_contents\":[\"I\",\"I\",\"I\"]},\"data\":\"827961c8-07b6-4e43-92e4-ad118cacac4d\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"II\",\"shape\":\"triangle-up\",\"tooltip_contents\":[\"II\",\"II\"]},\"data\":\"f05f2c4a-627e-44df-8b35-985718e0dde8\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"III\",\"shape\":\"diamond\",\"tooltip_contents\":[\"III\",\"III\"]},\"data\":\"3f90c3cf-18f4-4789-9ddd-c2dbbac066c9\"}],\"options\":{\"legend\":true,\"zoom\":true,\"width\":800,\"xrange\":[-10,10],\"yrange\":[-10,10]}}],\"data\":{\"827961c8-07b6-4e43-92e4-ad118cacac4d\":[{\"a\":1,\"b\":3},{\"a\":4,\"b\":3},{\"a\":5,\"b\":2}],\"f05f2c4a-627e-44df-8b35-985718e0dde8\":[{\"a\":2,\"b\":1},{\"a\":0,\"b\":0}],\"3f90c3cf-18f4-4789-9ddd-c2dbbac066c9\":[{\"a\":-2,\"b\":-6},{\"a\":23,\"b\":1}]},\"extension\":[]}\n",
       "        var id_name = '#vis-c959743a-7a5f-472a-9399-2eb8bb4b0978';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Plot:0x007fd05c1db378 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05c9a8bc8 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"I\", :shape=>\"circle\", :tooltip_contents=>[\"I\", \"I\", \"I\"]}, :data=>\"827961c8-07b6-4e43-92e4-ad118cacac4d\"}, @xrange=[1, 5], @yrange=[2, 3]>, #<Nyaplot::Diagram:0x007fd05baabfa8 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"II\", :shape=>\"triangle-up\", :tooltip_contents=>[\"II\", \"II\"]}, :data=>\"f05f2c4a-627e-44df-8b35-985718e0dde8\"}, @xrange=[0, 2], @yrange=[0, 1]>, #<Nyaplot::Diagram:0x007fd05c1d2098 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"III\", :shape=>\"diamond\", :tooltip_contents=>[\"III\", \"III\"]}, :data=>\"3f90c3cf-18f4-4789-9ddd-c2dbbac066c9\"}, @xrange=[-2, 23], @yrange=[-6, 1]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[-10, 10], :yrange=>[-10, 10]}}>"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scatter_2.chart.xrange [-10, 10]\n",
    "scatter_2.chart.yrange [-10, 10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-a4e5b8fd-b9c6-4808-9297-8e1d0a08f17e'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"I\",\"color\":\"red\",\"tooltip_contents\":[\"I\",\"I\",\"I\"]},\"data\":\"5b8a7ee4-3210-492b-886e-d641848b8778\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"II\",\"color\":\"blue\",\"tooltip_contents\":[\"II\",\"II\"]},\"data\":\"37a84466-b577-46f8-a015-86e200739f0c\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"III\",\"color\":\"green\",\"tooltip_contents\":[\"III\",\"III\"]},\"data\":\"188bbf12-a236-43d8-852c-e66cddbead9e\"}],\"options\":{\"legend\":true,\"zoom\":true,\"width\":800,\"xrange\":[-2,23],\"yrange\":[-6,3]}}],\"data\":{\"5b8a7ee4-3210-492b-886e-d641848b8778\":[{\"a\":1,\"b\":3},{\"a\":4,\"b\":3},{\"a\":5,\"b\":2}],\"37a84466-b577-46f8-a015-86e200739f0c\":[{\"a\":2,\"b\":1},{\"a\":0,\"b\":0}],\"188bbf12-a236-43d8-852c-e66cddbead9e\":[{\"a\":-2,\"b\":-6},{\"a\":23,\"b\":1}]},\"extension\":[]}\n",
       "        var id_name = '#vis-a4e5b8fd-b9c6-4808-9297-8e1d0a08f17e';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Frame:0x007fd05c12b5e0 @properties={:panes=>[#<Nyaplot::Plot:0x007fd05c16a1c8 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05c158040 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"I\", :color=>:red, :tooltip_contents=>[\"I\", \"I\", \"I\"]}, :data=>\"5b8a7ee4-3210-492b-886e-d641848b8778\"}, @xrange=[1, 5], @yrange=[2, 3]>, #<Nyaplot::Diagram:0x007fd05c13b210 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"II\", :color=>:blue, :tooltip_contents=>[\"II\", \"II\"]}, :data=>\"37a84466-b577-46f8-a015-86e200739f0c\"}, @xrange=[0, 2], @yrange=[0, 1]>, #<Nyaplot::Diagram:0x007fd05c1311e8 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"III\", :color=>:green, :tooltip_contents=>[\"III\", \"III\"]}, :data=>\"188bbf12-a236-43d8-852c-e66cddbead9e\"}, @xrange=[-2, 23], @yrange=[-6, 1]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[-2, 23], :yrange=>[-6, 3]}}>], :data=>{\"5b8a7ee4-3210-492b-886e-d641848b8778\"=>#<Nyaplot::DataFrame:0x007fd05c158838 @name=\"5b8a7ee4-3210-492b-886e-d641848b8778\", @rows=[{:a=>1, :b=>3}, {:a=>4, :b=>3}, {:a=>5, :b=>2}]>, \"37a84466-b577-46f8-a015-86e200739f0c\"=>#<Nyaplot::DataFrame:0x007fd05c13b760 @name=\"37a84466-b577-46f8-a015-86e200739f0c\", @rows=[{:a=>2, :b=>1}, {:a=>0, :b=>0}]>, \"188bbf12-a236-43d8-852c-e66cddbead9e\"=>#<Nyaplot::DataFrame:0x007fd05c1315d0 @name=\"188bbf12-a236-43d8-852c-e66cddbead9e\", @rows=[{:a=>-2, :b=>-6}, {:a=>23, :b=>1}]>}, :extension=>[]}>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div id='vis-7eefae9c-5917-4cd4-ba89-77827220a672'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"I\",\"shape\":\"circle\",\"tooltip_contents\":[\"I\",\"I\",\"I\"]},\"data\":\"827961c8-07b6-4e43-92e4-ad118cacac4d\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"II\",\"shape\":\"triangle-up\",\"tooltip_contents\":[\"II\",\"II\"]},\"data\":\"f05f2c4a-627e-44df-8b35-985718e0dde8\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"III\",\"shape\":\"diamond\",\"tooltip_contents\":[\"III\",\"III\"]},\"data\":\"3f90c3cf-18f4-4789-9ddd-c2dbbac066c9\"}],\"options\":{\"legend\":true,\"zoom\":true,\"width\":800,\"xrange\":[-10,10],\"yrange\":[-10,10]}}],\"data\":{\"827961c8-07b6-4e43-92e4-ad118cacac4d\":[{\"a\":1,\"b\":3},{\"a\":4,\"b\":3},{\"a\":5,\"b\":2}],\"f05f2c4a-627e-44df-8b35-985718e0dde8\":[{\"a\":2,\"b\":1},{\"a\":0,\"b\":0}],\"3f90c3cf-18f4-4789-9ddd-c2dbbac066c9\":[{\"a\":-2,\"b\":-6},{\"a\":23,\"b\":1}]},\"extension\":[]}\n",
       "        var id_name = '#vis-7eefae9c-5917-4cd4-ba89-77827220a672';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Plot:0x007fd05c1db378 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05c9a8bc8 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"I\", :shape=>\"circle\", :tooltip_contents=>[\"I\", \"I\", \"I\"]}, :data=>\"827961c8-07b6-4e43-92e4-ad118cacac4d\"}, @xrange=[1, 5], @yrange=[2, 3]>, #<Nyaplot::Diagram:0x007fd05baabfa8 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"II\", :shape=>\"triangle-up\", :tooltip_contents=>[\"II\", \"II\"]}, :data=>\"f05f2c4a-627e-44df-8b35-985718e0dde8\"}, @xrange=[0, 2], @yrange=[0, 1]>, #<Nyaplot::Diagram:0x007fd05c1d2098 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"III\", :shape=>\"diamond\", :tooltip_contents=>[\"III\", \"III\"]}, :data=>\"3f90c3cf-18f4-4789-9ddd-c2dbbac066c9\"}, @xrange=[-2, 23], @yrange=[-6, 1]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[-10, 10], :yrange=>[-10, 10]}}>"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scatter_3 = Daru::View::Plot.new(df, type: :scatter, x: :a, y: :b, categorized: {by: :c, method: :color, color: [:red, :blue, :green]})\n",
    "scatter_3.show_in_iruby\n",
    "scatter_2.chart.xrange [-10, 10]\n",
    "scatter_2.chart.yrange [-10, 10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-8ae12741-1caa-44e4-87c3-8adf87119c10'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"I\",\"size\":300,\"tooltip_contents\":[\"I\",\"I\",\"I\"]},\"data\":\"b7fadd95-2003-4643-90e5-336cbaff1af4\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"II\",\"size\":600,\"tooltip_contents\":[\"II\",\"II\"]},\"data\":\"38bb6200-a8ed-4a87-9ca1-ec7edabeab48\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"III\",\"size\":900,\"tooltip_contents\":[\"III\",\"III\"]},\"data\":\"25caef61-eaa1-4c73-a8b7-031dbb8b1b9f\"}],\"options\":{\"legend\":true,\"zoom\":true,\"width\":800,\"xrange\":[-2,23],\"yrange\":[-6,3]}}],\"data\":{\"b7fadd95-2003-4643-90e5-336cbaff1af4\":[{\"a\":1,\"b\":3},{\"a\":4,\"b\":3},{\"a\":5,\"b\":2}],\"38bb6200-a8ed-4a87-9ca1-ec7edabeab48\":[{\"a\":2,\"b\":1},{\"a\":0,\"b\":0}],\"25caef61-eaa1-4c73-a8b7-031dbb8b1b9f\":[{\"a\":-2,\"b\":-6},{\"a\":23,\"b\":1}]},\"extension\":[]}\n",
       "        var id_name = '#vis-8ae12741-1caa-44e4-87c3-8adf87119c10';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Frame:0x007fd05c9743a0 @properties={:panes=>[#<Nyaplot::Plot:0x007fd05b191530 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05b181a40 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"I\", :size=>300, :tooltip_contents=>[\"I\", \"I\", \"I\"]}, :data=>\"b7fadd95-2003-4643-90e5-336cbaff1af4\"}, @xrange=[1, 5], @yrange=[2, 3]>, #<Nyaplot::Diagram:0x007fd05b172040 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"II\", :size=>600, :tooltip_contents=>[\"II\", \"II\"]}, :data=>\"38bb6200-a8ed-4a87-9ca1-ec7edabeab48\"}, @xrange=[0, 2], @yrange=[0, 1]>, #<Nyaplot::Diagram:0x007fd05c975b38 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"III\", :size=>900, :tooltip_contents=>[\"III\", \"III\"]}, :data=>\"25caef61-eaa1-4c73-a8b7-031dbb8b1b9f\"}, @xrange=[-2, 23], @yrange=[-6, 1]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[-2, 23], :yrange=>[-6, 3]}}>], :data=>{\"b7fadd95-2003-4643-90e5-336cbaff1af4\"=>#<Nyaplot::DataFrame:0x007fd05b182058 @name=\"b7fadd95-2003-4643-90e5-336cbaff1af4\", @rows=[{:a=>1, :b=>3}, {:a=>4, :b=>3}, {:a=>5, :b=>2}]>, \"38bb6200-a8ed-4a87-9ca1-ec7edabeab48\"=>#<Nyaplot::DataFrame:0x007fd05b172478 @name=\"38bb6200-a8ed-4a87-9ca1-ec7edabeab48\", @rows=[{:a=>2, :b=>1}, {:a=>0, :b=>0}]>, \"25caef61-eaa1-4c73-a8b7-031dbb8b1b9f\"=>#<Nyaplot::DataFrame:0x007fd05c976948 @name=\"25caef61-eaa1-4c73-a8b7-031dbb8b1b9f\", @rows=[{:a=>-2, :b=>-6}, {:a=>23, :b=>1}]>}, :extension=>[]}>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div id='vis-5f9addad-0d19-47e0-95e3-929b47b873f0'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"I\",\"size\":300,\"tooltip_contents\":[\"I\",\"I\",\"I\"]},\"data\":\"b7fadd95-2003-4643-90e5-336cbaff1af4\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"II\",\"size\":600,\"tooltip_contents\":[\"II\",\"II\"]},\"data\":\"38bb6200-a8ed-4a87-9ca1-ec7edabeab48\"},{\"type\":\"scatter\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"III\",\"size\":900,\"tooltip_contents\":[\"III\",\"III\"]},\"data\":\"25caef61-eaa1-4c73-a8b7-031dbb8b1b9f\"}],\"options\":{\"legend\":true,\"zoom\":true,\"width\":800,\"xrange\":[-10,10],\"yrange\":[-10,10]}}],\"data\":{\"b7fadd95-2003-4643-90e5-336cbaff1af4\":[{\"a\":1,\"b\":3},{\"a\":4,\"b\":3},{\"a\":5,\"b\":2}],\"38bb6200-a8ed-4a87-9ca1-ec7edabeab48\":[{\"a\":2,\"b\":1},{\"a\":0,\"b\":0}],\"25caef61-eaa1-4c73-a8b7-031dbb8b1b9f\":[{\"a\":-2,\"b\":-6},{\"a\":23,\"b\":1}]},\"extension\":[]}\n",
       "        var id_name = '#vis-5f9addad-0d19-47e0-95e3-929b47b873f0';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Plot:0x007fd05b191530 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05b181a40 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"I\", :size=>300, :tooltip_contents=>[\"I\", \"I\", \"I\"]}, :data=>\"b7fadd95-2003-4643-90e5-336cbaff1af4\"}, @xrange=[1, 5], @yrange=[2, 3]>, #<Nyaplot::Diagram:0x007fd05b172040 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"II\", :size=>600, :tooltip_contents=>[\"II\", \"II\"]}, :data=>\"38bb6200-a8ed-4a87-9ca1-ec7edabeab48\"}, @xrange=[0, 2], @yrange=[0, 1]>, #<Nyaplot::Diagram:0x007fd05c975b38 @properties={:type=>:scatter, :options=>{:x=>:a, :y=>:b, :title=>\"III\", :size=>900, :tooltip_contents=>[\"III\", \"III\"]}, :data=>\"25caef61-eaa1-4c73-a8b7-031dbb8b1b9f\"}, @xrange=[-2, 23], @yrange=[-6, 1]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[-10, 10], :yrange=>[-10, 10]}}>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scatter_4 = Daru::View::Plot.new(df, type: :scatter, x: :a, y: :b, categorized: {by: :c, method: :size, size: [300, 600, 900]})\n",
    "scatter_4.show_in_iruby\n",
    "scatter_4.chart.xrange [-10, 10]\n",
    "scatter_4.chart.yrange [-10, 10]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Line plot categorized by categorical variable\n",
    "It works similar to Scatter plot above and all options are same except that there's no categorization by size but instead there is categorization by stroke_width in line plots."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       ":category"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = Daru::DataFrame.new({\n",
    "  a: [1, 2, 3, 4, 5, 6, 7, 8, 9],\n",
    "  b: [2, 4, 6, 1, 3, 5, 6, 4, 3],\n",
    "  c: ['I']*3 + ['II']*3 + ['III']*3\n",
    "  })\n",
    "df.to_category :c\n",
    "df[:c].type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-ee6e186c-7412-4aa0-a06f-a5c385f4e2ba'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"line\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"I\",\"color\":\"rgb(251,180,174)\"},\"data\":\"a49ceebd-9f3b-4d47-a770-e43135c06253\"},{\"type\":\"line\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"II\",\"color\":\"rgb(179,205,227)\"},\"data\":\"6dc7ffb8-5005-486e-bd44-2346eee11c00\"},{\"type\":\"line\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"III\",\"color\":\"rgb(204,235,197)\"},\"data\":\"b53af3ce-b6f5-4713-87f4-c7bd17d83233\"}],\"options\":{\"legend\":true,\"zoom\":true,\"width\":800,\"xrange\":[1,9],\"yrange\":[1,6]}}],\"data\":{\"a49ceebd-9f3b-4d47-a770-e43135c06253\":[{\"a\":1,\"b\":2},{\"a\":2,\"b\":4},{\"a\":3,\"b\":6}],\"6dc7ffb8-5005-486e-bd44-2346eee11c00\":[{\"a\":4,\"b\":1},{\"a\":5,\"b\":3},{\"a\":6,\"b\":5}],\"b53af3ce-b6f5-4713-87f4-c7bd17d83233\":[{\"a\":7,\"b\":6},{\"a\":8,\"b\":4},{\"a\":9,\"b\":3}]},\"extension\":[]}\n",
       "        var id_name = '#vis-ee6e186c-7412-4aa0-a06f-a5c385f4e2ba';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Frame:0x007fd05c8f4ba0 @properties={:panes=>[#<Nyaplot::Plot:0x007fd05b06bac0 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05b049ad8 @properties={:type=>:line, :options=>{:x=>:a, :y=>:b, :title=>\"I\", :color=>\"rgb(251,180,174)\"}, :data=>\"a49ceebd-9f3b-4d47-a770-e43135c06253\"}, @xrange=[1, 3], @yrange=[2, 6]>, #<Nyaplot::Diagram:0x007fd05c936ff0 @properties={:type=>:line, :options=>{:x=>:a, :y=>:b, :title=>\"II\", :color=>\"rgb(179,205,227)\"}, :data=>\"6dc7ffb8-5005-486e-bd44-2346eee11c00\"}, @xrange=[4, 6], @yrange=[1, 5]>, #<Nyaplot::Diagram:0x007fd05c8fe150 @properties={:type=>:line, :options=>{:x=>:a, :y=>:b, :title=>\"III\", :color=>\"rgb(204,235,197)\"}, :data=>\"b53af3ce-b6f5-4713-87f4-c7bd17d83233\"}, @xrange=[7, 9], @yrange=[3, 6]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[1, 9], :yrange=>[1, 6]}}>], :data=>{\"a49ceebd-9f3b-4d47-a770-e43135c06253\"=>#<Nyaplot::DataFrame:0x007fd05b04aed8 @name=\"a49ceebd-9f3b-4d47-a770-e43135c06253\", @rows=[{:a=>1, :b=>2}, {:a=>2, :b=>4}, {:a=>3, :b=>6}]>, \"6dc7ffb8-5005-486e-bd44-2346eee11c00\"=>#<Nyaplot::DataFrame:0x007fd05c937ab8 @name=\"6dc7ffb8-5005-486e-bd44-2346eee11c00\", @rows=[{:a=>4, :b=>1}, {:a=>5, :b=>3}, {:a=>6, :b=>5}]>, \"b53af3ce-b6f5-4713-87f4-c7bd17d83233\"=>#<Nyaplot::DataFrame:0x007fd05c8ffde8 @name=\"b53af3ce-b6f5-4713-87f4-c7bd17d83233\", @rows=[{:a=>7, :b=>6}, {:a=>8, :b=>4}, {:a=>9, :b=>3}]>}, :extension=>[]}>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "line_1 = Daru::View::Plot.new(df, type: :line, x: :a, y: :b, categorized: {by: :c, method: :color})\n",
    "line_1.show_in_iruby"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div id='vis-bfe48f50-2780-41f1-8d72-609ab167eb26'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"line\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"I\",\"stroke_width\":2},\"data\":\"178c614d-0e82-4b7a-9dc2-a081206bc196\"},{\"type\":\"line\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"II\",\"stroke_width\":4},\"data\":\"ff20f4a8-f3c9-4103-9fa6-3ffc7204d9e2\"},{\"type\":\"line\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"III\",\"stroke_width\":6},\"data\":\"5f2efc6f-a1a2-40a5-84dc-88b900e1cded\"}],\"options\":{\"legend\":true,\"zoom\":true,\"width\":800,\"xrange\":[1,9],\"yrange\":[1,6]}}],\"data\":{\"178c614d-0e82-4b7a-9dc2-a081206bc196\":[{\"a\":1,\"b\":2},{\"a\":2,\"b\":4},{\"a\":3,\"b\":6}],\"ff20f4a8-f3c9-4103-9fa6-3ffc7204d9e2\":[{\"a\":4,\"b\":1},{\"a\":5,\"b\":3},{\"a\":6,\"b\":5}],\"5f2efc6f-a1a2-40a5-84dc-88b900e1cded\":[{\"a\":7,\"b\":6},{\"a\":8,\"b\":4},{\"a\":9,\"b\":3}]},\"extension\":[]}\n",
       "        var id_name = '#vis-bfe48f50-2780-41f1-8d72-609ab167eb26';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Frame:0x007fd05b8bd160 @properties={:panes=>[#<Nyaplot::Plot:0x007fd05c054270 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05c01c730 @properties={:type=>:line, :options=>{:x=>:a, :y=>:b, :title=>\"I\", :stroke_width=>2}, :data=>\"178c614d-0e82-4b7a-9dc2-a081206bc196\"}, @xrange=[1, 3], @yrange=[2, 6]>, #<Nyaplot::Diagram:0x007fd05c84eb60 @properties={:type=>:line, :options=>{:x=>:a, :y=>:b, :title=>\"II\", :stroke_width=>4}, :data=>\"ff20f4a8-f3c9-4103-9fa6-3ffc7204d9e2\"}, @xrange=[4, 6], @yrange=[1, 5]>, #<Nyaplot::Diagram:0x007fd05b0180f0 @properties={:type=>:line, :options=>{:x=>:a, :y=>:b, :title=>\"III\", :stroke_width=>6}, :data=>\"5f2efc6f-a1a2-40a5-84dc-88b900e1cded\"}, @xrange=[7, 9], @yrange=[3, 6]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[1, 9], :yrange=>[1, 6]}}>], :data=>{\"178c614d-0e82-4b7a-9dc2-a081206bc196\"=>#<Nyaplot::DataFrame:0x007fd05c02cb80 @name=\"178c614d-0e82-4b7a-9dc2-a081206bc196\", @rows=[{:a=>1, :b=>2}, {:a=>2, :b=>4}, {:a=>3, :b=>6}]>, \"ff20f4a8-f3c9-4103-9fa6-3ffc7204d9e2\"=>#<Nyaplot::DataFrame:0x007fd05c85c378 @name=\"ff20f4a8-f3c9-4103-9fa6-3ffc7204d9e2\", @rows=[{:a=>4, :b=>1}, {:a=>5, :b=>3}, {:a=>6, :b=>5}]>, \"5f2efc6f-a1a2-40a5-84dc-88b900e1cded\"=>#<Nyaplot::DataFrame:0x007fd05b018fa0 @name=\"5f2efc6f-a1a2-40a5-84dc-88b900e1cded\", @rows=[{:a=>7, :b=>6}, {:a=>8, :b=>4}, {:a=>9, :b=>3}]>}, :extension=>[]}>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div id='vis-12367786-a326-4f34-866f-84391cf29311'></div>\n",
       "<script>\n",
       "(function(){\n",
       "    var render = function(){\n",
       "        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"line\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"I\",\"stroke_width\":2},\"data\":\"178c614d-0e82-4b7a-9dc2-a081206bc196\"},{\"type\":\"line\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"II\",\"stroke_width\":4},\"data\":\"ff20f4a8-f3c9-4103-9fa6-3ffc7204d9e2\"},{\"type\":\"line\",\"options\":{\"x\":\"a\",\"y\":\"b\",\"title\":\"III\",\"stroke_width\":6},\"data\":\"5f2efc6f-a1a2-40a5-84dc-88b900e1cded\"}],\"options\":{\"legend\":true,\"zoom\":true,\"width\":800,\"xrange\":[-10,10],\"yrange\":[-10,10]}}],\"data\":{\"178c614d-0e82-4b7a-9dc2-a081206bc196\":[{\"a\":1,\"b\":2},{\"a\":2,\"b\":4},{\"a\":3,\"b\":6}],\"ff20f4a8-f3c9-4103-9fa6-3ffc7204d9e2\":[{\"a\":4,\"b\":1},{\"a\":5,\"b\":3},{\"a\":6,\"b\":5}],\"5f2efc6f-a1a2-40a5-84dc-88b900e1cded\":[{\"a\":7,\"b\":6},{\"a\":8,\"b\":4},{\"a\":9,\"b\":3}]},\"extension\":[]}\n",
       "        var id_name = '#vis-12367786-a326-4f34-866f-84391cf29311';\n",
       "        Nyaplot.core.parse(model, id_name);\n",
       "\n",
       "        require(['downloadable'], function(downloadable){\n",
       "          var svg = d3.select(id_name).select(\"svg\");\n",
       "\t  if(!svg.empty())\n",
       "\t    svg.call(downloadable().filename('fig'));\n",
       "\t});\n",
       "    };\n",
       "    if(window['Nyaplot']==undefined){\n",
       "        window.addEventListener('load_nyaplot', render, false);\n",
       "\treturn;\n",
       "    } else {\n",
       "       render();\n",
       "    }\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "#<Nyaplot::Plot:0x007fd05c054270 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fd05c01c730 @properties={:type=>:line, :options=>{:x=>:a, :y=>:b, :title=>\"I\", :stroke_width=>2}, :data=>\"178c614d-0e82-4b7a-9dc2-a081206bc196\"}, @xrange=[1, 3], @yrange=[2, 6]>, #<Nyaplot::Diagram:0x007fd05c84eb60 @properties={:type=>:line, :options=>{:x=>:a, :y=>:b, :title=>\"II\", :stroke_width=>4}, :data=>\"ff20f4a8-f3c9-4103-9fa6-3ffc7204d9e2\"}, @xrange=[4, 6], @yrange=[1, 5]>, #<Nyaplot::Diagram:0x007fd05b0180f0 @properties={:type=>:line, :options=>{:x=>:a, :y=>:b, :title=>\"III\", :stroke_width=>6}, :data=>\"5f2efc6f-a1a2-40a5-84dc-88b900e1cded\"}, @xrange=[7, 9], @yrange=[3, 6]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[-10, 10], :yrange=>[-10, 10]}}>"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "line_2 = Daru::View::Plot.new(df, type: :line, x: :a, y: :b, categorized: {by: :c, method: :stroke_width})\n",
    "line_2.show_in_iruby\n",
    "line_2.chart.xrange [-10, 10]\n",
    "line_2.chart.yrange [-10, 10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Ruby 2.3.1",
   "language": "ruby",
   "name": "ruby"
  },
  "language_info": {
   "file_extension": ".rb",
   "mimetype": "application/x-ruby",
   "name": "ruby",
   "version": "2.3.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}