{ "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": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/javascript": [ "\n", " /* BEGIN google_visualr.js */\n", "\n", "if(!window['googleLT_']){window['googleLT_']=(new Date()).getTime();}if (!window['google']) {\n", "window['google'] = {};\n", "}\n", "if (!window['google']['loader']) {\n", "window['google']['loader'] = {};\n", "google.loader.ServiceBase = 'https://www.google.com/uds';\n", "google.loader.GoogleApisBase = 'https://ajax.googleapis.com/ajax';\n", "google.loader.ApiKey = 'notsupplied';\n", "google.loader.KeyVerified = true;\n", "google.loader.LoadFailure = false;\n", "google.loader.Secure = true;\n", "google.loader.GoogleLocale = 'www.google.com';\n", "google.loader.ClientLocation = null;\n", "google.loader.AdditionalParams = '';\n", "(function() {function g(a){return a in l?l[a]:l[a]=-1!=navigator.userAgent.toLowerCase().indexOf(a)}var l={};function m(a,b){var c=function(){};c.prototype=b.prototype;a.ca=b.prototype;a.prototype=new c}function n(a,b,c){var d=Array.prototype.slice.call(arguments,2)||[];return function(){return a.apply(b,d.concat(Array.prototype.slice.call(arguments)))}}function p(a){a=Error(a);a.toString=function(){return this.message};return a}\n", "function q(a,b){a=a.split(/\\./);for(var c=window,d=0;d\\x3c/script>\"):(g(\"safari\")||g(\"konqueror\"))&&window.setTimeout(B,10)),x.push(a)):y(window,\"load\",a)};t(\"google.setOnLoadCallback\",google.ba);\n", "function y(a,b,c){if(a.addEventListener)a.addEventListener(b,c,!1);else if(a.attachEvent)a.attachEvent(\"on\"+b,c);else{var d=a[\"on\"+b];a[\"on\"+b]=null!=d?C([c,d]):c}}function C(a){return function(){for(var b=0;b\\x3c/script>'):\"css\"==a&&document.write('')};\n", "t(\"google.loader.writeLoadTag\",google.loader.f);google.loader.Z=function(a){w=a};t(\"google.loader.rfm\",google.loader.Z);google.loader.aa=function(a){for(var b in a)\"string\"==typeof b&&b&&\":\"==b.charAt(0)&&!v[b]&&(v[b]=new E(b.substring(1),a[b]))};t(\"google.loader.rpl\",google.loader.aa);google.loader.$=function(a){if((a=a.specs)&&a.length)for(var b=0;b\\x3c/script>')},K.Mi=function(b){var c=K.global.document,d=c.createElement(\"script\");d.type=C;d.src=b;d.defer=!1;d.async=!1;c.head.appendChild(d)},\n", "K.Wl=function(b,c){if(K.tg()){var d=K.global.document;if(!K.Ge&&d.readyState==t){if(/\\bdeps.js$/.test(b))return!1;throw Error('Cannot write \"'+b+'\" after document load');}void 0===c?K.fi?(K.eh=!0,c=\" onreadystatechange='goog.onScriptLoad_(this, \"+ ++K.Sg+\")' \",d.write(n+b+'\"'+c+\">\\x3c/script>\")):K.Ge?K.Mi(b):K.Vl(b):d.write('\n" ], "text/plain": [ "#\"number\", :label=>\"Age\"}, {:type=>\"number\", :label=>\"Weight\"}], @rows=[[#, #], [#, #], [#, #], [#, #], [#, #], [#, #]], @options={:pageSize=>5, :height=>200, :width=>100}>" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scatter_table = Daru::View::Table.new(df_age_wt, pageSize: 5, height: 200, width: 100)\n", "scatter_table.table" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scatter_options = {\n", " title: 'Age vs. Weight comparison',\n", " hAxis: {title: 'Age', minValue: 0, maxValue: 15},\n", " vAxis: {title: 'Weight', minValue: 0, maxValue: 15},\n", " legend: 'none',\n", " type: :scatter\n", " }\n", "scatter_chart = Daru::View::Plot.new(\n", " scatter_table.table, scatter_options)\n", "scatter_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Creating Material scatter charts" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(50x2) \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "
Hours StudiedFinal
0067
1188
2277
3393
4485
5591
6671
7778
8893
9980
101082
11075
12580
13390
14172
15575
16668
17798
18382
19994
20279
21295
22286
23367
24460
25280
26692
27281
28879
29983
.........
49998
" ], "text/plain": [ "#\n", " Hours Stud Final\n", " 0 0 67\n", " 1 1 88\n", " 2 2 77\n", " 3 3 93\n", " 4 4 85\n", " 5 5 91\n", " 6 6 71\n", " 7 7 78\n", " 8 8 93\n", " 9 9 80\n", " 10 10 82\n", " 11 0 75\n", " 12 5 80\n", " 13 3 90\n", " 14 1 72\n", " ... ... ..." ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idx = Daru::Index.new ['Hours Studied', 'Final']\n", "data_rows = [\n", " [0, 67], [1, 88], [2, 77],\n", " [3, 93], [4, 85], [5, 91],\n", " [6, 71], [7, 78], [8, 93],\n", " [9, 80], [10, 82],[0, 75],\n", " [5, 80], [3, 90], [1, 72],\n", " [5, 75], [6, 68], [7, 98],\n", " [3, 82], [9, 94], [2, 79],\n", " [2, 95], [2, 86], [3, 67],\n", " [4, 60], [2, 80], [6, 92],\n", " [2, 81], [8, 79], [9, 83],\n", " [3, 75], [1, 80], [3, 71],\n", " [3, 89], [4, 92], [5, 85],\n", " [6, 92], [7, 78], [6, 95],\n", " [3, 81], [0, 64], [4, 85],\n", " [2, 83], [3, 96], [4, 77],\n", " [5, 89], [4, 89], [7, 84],\n", " [4, 92], [9, 98]\n", "]\n", "df_study_hours = Daru::DataFrame.rows(data_rows)\n", "df_study_hours.vectors = idx\n", "df_study_hours\n", "\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "#\"number\", :label=>\"Hours Studied\"}, {:type=>\"number\", :label=>\"Final\"}], @rows=[[#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #]], @options={:pageSize=>10, :height=>300, :width=>200}>" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scatter_material_table = Daru::View::Table.new(df_study_hours, pageSize: 10, height: 300, width: 200)\n", "scatter_material_table.table" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scatter_material_options = {\n", " width: 800,\n", " height: 500,\n", " chart: {\n", " title: 'Students\\' Final Grades',\n", " subtitle: 'based on hours studied'\n", " },\n", " hAxis: {title: 'Hours Studied'},\n", " vAxis: {title: 'Grade'},\n", " type: :scatter\n", " }\n", "scatter_material_chart = Daru::View::Plot.new(\n", " scatter_material_table.table, scatter_material_options)\n", "scatter_material_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Dual-Y charts" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(30x3) \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", "
Student IDHours StudiedFinal
00067
11188
22277
33393
44485
55591
66671
77778
88893
99980
10101082
1111075
1212580
1313390
1414172
1515575
1616668
1717798
1818382
1919994
2020279
2121295
2222286
2323367
2424460
2525280
2626692
2727281
2828879
2929983
" ], "text/plain": [ "#\n", " Student ID Hours Stud Final\n", " 0 0 0 67\n", " 1 1 1 88\n", " 2 2 2 77\n", " 3 3 3 93\n", " 4 4 4 85\n", " 5 5 5 91\n", " 6 6 6 71\n", " 7 7 7 78\n", " 8 8 8 93\n", " 9 9 9 80\n", " 10 10 10 82\n", " 11 11 0 75\n", " 12 12 5 80\n", " 13 13 3 90\n", " 14 14 1 72\n", " ... ... ... ..." ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idx = Daru::Index.new ['Student ID', 'Hours Studied', 'Final']\n", "data_rows = [\n", " [0, 0, 67], [1, 1, 88], [2, 2, 77],\n", " [3, 3, 93], [4, 4, 85], [5, 5, 91],\n", " [6, 6, 71], [7, 7, 78], [8, 8, 93],\n", " [9, 9, 80], [10, 10, 82], [11, 0, 75],\n", " [12, 5, 80], [13, 3, 90], [14, 1, 72],\n", " [15, 5, 75], [16, 6, 68], [17, 7, 98],\n", " [18, 3, 82], [19, 9, 94], [20, 2, 79],\n", " [21, 2, 95], [22, 2, 86], [23, 3, 67],\n", " [24, 4, 60], [25, 2, 80], [26, 6, 92],\n", " [27, 2, 81], [28, 8, 79], [29, 9, 83]\n", "]\n", "df_id_study_hours = Daru::DataFrame.rows(data_rows)\n", "df_id_study_hours.vectors = idx\n", "df_id_study_hours\n", "\n" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "#\"number\", :label=>\"Student ID\"}, {:type=>\"number\", :label=>\"Hours Studied\"}, {:type=>\"number\", :label=>\"Final\"}], @rows=[[#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #]], @options={:pageSize=>10, :height=>300, :width=>300}>" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scatter_dualY_table = Daru::View::Table.new(df_id_study_hours, pageSize: 10, height: 300, width: 300)\n", "scatter_dualY_table.table" ] }, { "cell_type": "code", "execution_count": 48, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scatter_dualY_options = {\n", " chart: {\n", " title: 'Students\\' Final Grades',\n", " subtitle: 'based on hours studied'\n", " },\n", " width: 800,\n", " height: 500,\n", "# FixMe: There is some problem in below code execution. So similar charts \n", "# options is not working from this \n", "# link : https://developers.google.com/chart/interactive/docs/gallery/scatterchart#fullhtml\n", "# series: {\n", "# '0': {axis: 'hours studied'},\n", "# '1': {axis: 'final grade'}\n", "# },\n", "# axes: {\n", "# y: {\n", "# 'hours studied': {label: 'Hours Studied'},\n", "# 'final grade': {label: 'Final Exam Grade'}\n", "# }\n", "# },\n", " type: :scatter\n", "}\n", "scatter_dualY_chart = Daru::View::Plot.new(\n", " scatter_dualY_table.table, scatter_dualY_options)\n", "scatter_dualY_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "TODO: Other examples from this link: https://developers.google.com/chart/interactive/docs/gallery/scatterchart#fullhtml" ] }, { "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 }