{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creating Boxplots with daru and statsample\n", "\n", "### Description\n", "\n", "This example illustrates how daru, combined with Statsample::Graph::Boxplot\n", "can be used for generating box plots of a normally distributed set of data.\n", "\n", "The 'rnorm' function, defined in statsample/shorthands generates a Daru::Vector\n", "object which contains the specified number of random variables in a normal distribution.\n", "It uses the 'distribution' gem for this purpose." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "data": { "text/plain": [ "Daru::Vector" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "require 'daru'\n", "require 'statsample'\n", "include Statsample::Shorthand\n", "\n", "n = 30\n", "a = rnorm(n-1,50,10)\n", "b = rnorm(n, 30,5)\n", "c = rnorm(n,5,1)\n", "a.push(2)\n", "\n", "a.class" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "#[#[#:scatter, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"da5a166d-0062-4ea7-a8a4-97a88d8344f4\"}, @xrange=[0, 29], @yrange=[2, 78.55948349140391]>], :options=>{:zoom=>true, :width=>700, :xrange=>[0, 29], :yrange=>[2, 78.55948349140391]}}>], :data=>{\"da5a166d-0062-4ea7-a8a4-97a88d8344f4\"=>#0, :data1=>38.30971413680693}, {:data0=>1, :data1=>55.44387982490567}, {:data0=>2, :data1=>45.76519338095696}, {:data0=>3, :data1=>56.005193440590986}, {:data0=>4, :data1=>59.72251047251204}, {:data0=>5, :data1=>50.486217817164395}, {:data0=>6, :data1=>57.04538860223644}, {:data0=>7, :data1=>24.076541667218926}, {:data0=>8, :data1=>58.877071960799064}, {:data0=>9, :data1=>45.93014563731179}, {:data0=>10, :data1=>59.37772697796843}, {:data0=>11, :data1=>42.95819596171652}, {:data0=>12, :data1=>58.92061969024059}, {:data0=>13, :data1=>39.426675104618155}, {:data0=>14, :data1=>48.25115168826487}, {:data0=>15, :data1=>53.835700573183}, {:data0=>16, :data1=>57.3372477889954}, {:data0=>17, :data1=>41.538072731617056}, {:data0=>18, :data1=>78.55948349140391}, {:data0=>19, :data1=>56.2110309713634}, {:data0=>20, :data1=>43.68845501421002}, {:data0=>21, :data1=>49.75094921116981}, {:data0=>22, :data1=>50.04177270608168}, {:data0=>23, :data1=>38.71961201083437}, {:data0=>24, :data1=>48.99456130060846}, {:data0=>25, :data1=>48.67995207640971}, {:data0=>26, :data1=>39.935161526817645}, {:data0=>27, :data1=>50.978744991372004}, {:data0=>28, :data1=>54.455956868504416}, {:data0=>29, :data1=>2}]>}, :extension=>[]}>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "a.plot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Create a boxplot of the data by specifying the vectors a, b and c and providing necessary options to Statsample::Graph::Boxplot. \n", "\n", "#### The `#to_svg` function returns the boxplot image in a raw SVG format. To display this properly in iruby we need to pass that output to the `IRuby.svg` method." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/svg+xml": [ "010203040506070" ], "text/plain": [ "\"010203040506070\"" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IRuby.svg boxplot(:vectors=>[a,b,c],:width=>300, :height=>300, :groups=>%w{first first second}, :minimum=>0).to_svg" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "IRuby.svg boxplot(:vectors=>[a,b,c],:width=>300, :height=>300, :groups=>%w{first first second}, :minimum=>0).to_svg" ] } ], "metadata": { "kernelspec": { "display_name": "Ruby 2.2.1", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": "rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "2.2.1" } }, "nbformat": 4, "nbformat_minor": 0 }