In [1]:
require 'daru/view'


Install the spreadsheet gem version ~>1.1.1 for using spreadsheet functions.

Install the mechanize gem version ~>2.7.5 for using mechanize functions.
Out[1]:
true

In [2]:
Daru::View.plotting_library = :googlecharts


Out[2]:
:googlecharts

In [3]:
data = [
 ['ID', 'Life Expectancy', 'Fertility Rate', 'Region',     'Population'],
        ['CAN',    80.66,              1.67,      'North America',  33739900],
        ['DEU',    79.84,              1.36,      'Europe',         81902307],
        ['DNK',    78.6,               1.84,      'Europe',         5523095],
        ['EGY',    72.73,              2.78,      'Middle East',    79716203],
        ['GBR',    80.05,              2,         'Europe',         61801570],
        ['IRN',    72.49,              1.7,       'Middle East',    73137148],
        ['IRQ',    68.09,              4.77,      'Middle East',    31090763],
        ['ISR',    81.55,              2.96,      'Middle East',    7485600],
        ['RUS',    68.6,               1.54,      'Europe',         141850000],
        ['USA',    78.09,              2.05,      'North America',  307007000]
  ]
bubble_chart_table = Daru::View::Table.new(data)
bubble_chart_table.show_in_iruby


Out[3]:

In [6]:
bubble_chart_options = {
  type: :bubble
}
bubble_chart_chart = Daru::View::Plot.new(bubble_chart_table.table, bubble_chart_options)
bubble_chart_chart.show_in_iruby


Out[6]:

In [7]:
bubble_chart_options = {
  height: 400,
  title: 'Correlation between life expectancy, fertility rate ' +
               'and population of some world countries (2010)',
        hAxis: {title: 'Life Expectancy'},
        vAxis: {title: 'Fertility Rate'},
        bubble: {textStyle: {fontSize: 11}},
  type: :bubble
}
bubble_chart_chart = Daru::View::Plot.new(bubble_chart_table.table, bubble_chart_options)
bubble_chart_chart.show_in_iruby


Out[7]:

Color By Numbers


In [8]:
idx = Daru::Index.new ['ID', 'X', 'Y', 'Temperature']
data_rows = [
          ['',   80,  167,      120],
          ['',   79,  136,      130],
          ['',   78,  184,      50],
          ['',   72,  278,      230],
          ['',   81,  200,      210],
          ['',   72,  170,      100],
          ['',   68,  477,      80]
  ]
df_color = Daru::DataFrame.rows(data_rows)
df_color.vectors = idx
df_color


Out[8]:
Daru::DataFrame(7x4)
ID X Y Temperature
0 80 167 120
1 79 136 130
2 78 184 50
3 72 278 230
4 81 200 210
5 72 170 100
6 68 477 80

In [10]:
bubble_chart_options = {
  type: :bubble
}
bubble_chart_chart = Daru::View::Plot.new(df_color, bubble_chart_options)
bubble_chart_chart.show_in_iruby


Out[10]:

In [11]:
bubble_chart_options = {
  colorAxis: {colors: ['yellow', 'red']},type: :bubble
}
bubble_chart_chart = Daru::View::Plot.new(df_color, bubble_chart_options)
bubble_chart_chart.show_in_iruby


Out[11]:

Customizing Labels


In [18]:
bubble_chart_options = {
  type: :bubble,
  title: 'Correlation between life expectancy, fertility rate ' +
           'and population of some world countries (2010)',
    hAxis: {title: 'Life Expectancy'},
    vAxis: {title: 'Fertility Rate'},
    bubble: {
      textStyle: {
        fontSize: 12,
        fontName: 'Comic Sans MS',
        color: 'green',
        bold: true,
        italic: true
      }
    }
}
bubble_chart_chart = Daru::View::Plot.new(bubble_chart_table.table, bubble_chart_options)
bubble_chart_chart.show_in_iruby


Out[18]:

In [19]:
bubble_chart_options = {
  type: :bubble,
title: 'Correlation between life expectancy, fertility rate ' +
           'and population of some world countries (2010)',
    hAxis: {title: 'Life Expectancy'},
    vAxis: {title: 'Fertility Rate'},
    bubble: {
      textStyle: {
        auraColor: 'none'
      }
    },
  height: 400
}
bubble_chart_chart = Daru::View::Plot.new(bubble_chart_table.table, bubble_chart_options)
bubble_chart_chart.show_in_iruby


Out[19]:

In [ ]: