{ "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": [ "\"
\\n\\n\"" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = [\n", " ['ID', 'Life Expectancy', 'Fertility Rate', 'Region', 'Population'],\n", " ['CAN', 80.66, 1.67, 'North America', 33739900],\n", " ['DEU', 79.84, 1.36, 'Europe', 81902307],\n", " ['DNK', 78.6, 1.84, 'Europe', 5523095],\n", " ['EGY', 72.73, 2.78, 'Middle East', 79716203],\n", " ['GBR', 80.05, 2, 'Europe', 61801570],\n", " ['IRN', 72.49, 1.7, 'Middle East', 73137148],\n", " ['IRQ', 68.09, 4.77, 'Middle East', 31090763],\n", " ['ISR', 81.55, 2.96, 'Middle East', 7485600],\n", " ['RUS', 68.6, 1.54, 'Europe', 141850000],\n", " ['USA', 78.09, 2.05, 'North America', 307007000]\n", " ]\n", "bubble_chart_table = Daru::View::Table.new(data)\n", "bubble_chart_table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "bubble_chart_options = {\n", " type: :bubble\n", "}\n", "bubble_chart_chart = Daru::View::Plot.new(bubble_chart_table.table, bubble_chart_options)\n", "bubble_chart_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "bubble_chart_options = {\n", " height: 400,\n", " title: 'Correlation between life expectancy, fertility rate ' +\n", " 'and population of some world countries (2010)',\n", " hAxis: {title: 'Life Expectancy'},\n", " vAxis: {title: 'Fertility Rate'},\n", " bubble: {textStyle: {fontSize: 11}},\n", " type: :bubble\n", "}\n", "bubble_chart_chart = Daru::View::Plot.new(bubble_chart_table.table, bubble_chart_options)\n", "bubble_chart_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Color By Numbers" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(7x4) \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", "
IDXYTemperature
080167120
179136130
27818450
372278230
481200210
572170100
66847780
" ], "text/plain": [ "#\n", " ID X Y Temperatur\n", " 0 80 167 120\n", " 1 79 136 130\n", " 2 78 184 50\n", " 3 72 278 230\n", " 4 81 200 210\n", " 5 72 170 100\n", " 6 68 477 80" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idx = Daru::Index.new ['ID', 'X', 'Y', 'Temperature']\n", "data_rows = [\n", " ['', 80, 167, 120],\n", " ['', 79, 136, 130],\n", " ['', 78, 184, 50],\n", " ['', 72, 278, 230],\n", " ['', 81, 200, 210],\n", " ['', 72, 170, 100],\n", " ['', 68, 477, 80]\n", " ]\n", "df_color = Daru::DataFrame.rows(data_rows)\n", "df_color.vectors = idx\n", "df_color" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "bubble_chart_options = {\n", " type: :bubble\n", "}\n", "bubble_chart_chart = Daru::View::Plot.new(df_color, bubble_chart_options)\n", "bubble_chart_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bubble_chart_options = {\n", " colorAxis: {colors: ['yellow', 'red']},type: :bubble\n", "}\n", "bubble_chart_chart = Daru::View::Plot.new(df_color, bubble_chart_options)\n", "bubble_chart_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Customizing Labels" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "bubble_chart_options = {\n", " type: :bubble,\n", " title: 'Correlation between life expectancy, fertility rate ' +\n", " 'and population of some world countries (2010)',\n", " hAxis: {title: 'Life Expectancy'},\n", " vAxis: {title: 'Fertility Rate'},\n", " bubble: {\n", " textStyle: {\n", " fontSize: 12,\n", " fontName: 'Comic Sans MS',\n", " color: 'green',\n", " bold: true,\n", " italic: true\n", " }\n", " }\n", "}\n", "bubble_chart_chart = Daru::View::Plot.new(bubble_chart_table.table, bubble_chart_options)\n", "bubble_chart_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "bubble_chart_options = {\n", " type: :bubble,\n", "title: 'Correlation between life expectancy, fertility rate ' +\n", " 'and population of some world countries (2010)',\n", " hAxis: {title: 'Life Expectancy'},\n", " vAxis: {title: 'Fertility Rate'},\n", " bubble: {\n", " textStyle: {\n", " auraColor: 'none'\n", " }\n", " },\n", " height: 400\n", "}\n", "bubble_chart_chart = Daru::View::Plot.new(bubble_chart_table.table, bubble_chart_options)\n", "bubble_chart_chart.show_in_iruby" ] }, { "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 }