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]:
idx = Daru::Index.new ['Dinosaur', 'Length']
data_rows = [
  ['Acrocanthosaurus (top-spined lizard)', 12.2],
          ['Albertosaurus (Alberta lizard)', 9.1],
          ['Allosaurus (other lizard)', 12.2],
          ['Apatosaurus (deceptive lizard)', 22.9],
          ['Archaeopteryx (ancient wing)', 0.9],
          ['Argentinosaurus (Argentina lizard)', 36.6],
          ['Baryonyx (heavy claws)', 9.1],
          ['Brachiosaurus (arm lizard)', 30.5],
          ['Ceratosaurus (horned lizard)', 6.1],
          ['Coelophysis (hollow form)', 2.7],
          ['Compsognathus (elegant jaw)', 0.9],
          ['Deinonychus (terrible claw)', 2.7],
          ['Diplodocus (double beam)', 27.1],
          ['Dromicelomimus (emu mimic)', 3.4],
          ['Gallimimus (fowl mimic)', 5.5],
          ['Mamenchisaurus (Mamenchi lizard)', 21.0],
          ['Megalosaurus (big lizard)', 7.9],
          ['Microvenator (small hunter)', 1.2],
          ['Ornithomimus (bird mimic)', 4.6],
          ['Oviraptor (egg robber)', 1.5],
          ['Plateosaurus (flat lizard)', 7.9],
          ['Sauronithoides (narrow-clawed lizard)', 2.0],
          ['Seismosaurus (tremor lizard)', 45.7],
          ['Spinosaurus (spiny lizard)', 12.2],
          ['Supersaurus (super lizard)', 30.5],
          ['Tyrannosaurus (tyrant lizard)', 15.2],
          ['Ultrasaurus (ultra lizard)', 30.5],
          ['Velociraptor (swift robber)', 1.8]
]
df_dino_length = Daru::DataFrame.rows(data_rows)
df_dino_length.vectors = idx
df_dino_length
Out[3]:
Daru::DataFrame(28x2)
Dinosaur Length
0 Acrocanthosaurus (top-spined lizard) 12.2
1 Albertosaurus (Alberta lizard) 9.1
2 Allosaurus (other lizard) 12.2
3 Apatosaurus (deceptive lizard) 22.9
4 Archaeopteryx (ancient wing) 0.9
5 Argentinosaurus (Argentina lizard) 36.6
6 Baryonyx (heavy claws) 9.1
7 Brachiosaurus (arm lizard) 30.5
8 Ceratosaurus (horned lizard) 6.1
9 Coelophysis (hollow form) 2.7
10 Compsognathus (elegant jaw) 0.9
11 Deinonychus (terrible claw) 2.7
12 Diplodocus (double beam) 27.1
13 Dromicelomimus (emu mimic) 3.4
14 Gallimimus (fowl mimic) 5.5
15 Mamenchisaurus (Mamenchi lizard) 21.0
16 Megalosaurus (big lizard) 7.9
17 Microvenator (small hunter) 1.2
18 Ornithomimus (bird mimic) 4.6
19 Oviraptor (egg robber) 1.5
20 Plateosaurus (flat lizard) 7.9
21 Sauronithoides (narrow-clawed lizard) 2.0
22 Seismosaurus (tremor lizard) 45.7
23 Spinosaurus (spiny lizard) 12.2
24 Supersaurus (super lizard) 30.5
25 Tyrannosaurus (tyrant lizard) 15.2
26 Ultrasaurus (ultra lizard) 30.5
27 Velociraptor (swift robber) 1.8
In [4]:
histo_table = Daru::View::Table.new(df_dino_length, height: 300, width: 200)
histo_table.show_in_iruby
Out[4]:

Note: Histogram chart doesn't work in google_visualr

In [6]:
histo_options = {
  title: 'Lengths of dinosaurs, in meters',
  legend: { position: 'none' },
   type: :histogram,
  height: 400
}
histo_chart = Daru::View::Plot.new(histo_table, histo_options)
histo_chart.show_in_iruby
Out[6]:
In [8]:
histo_options = {
  title: 'Lengths of dinosaurs, in meters',
  colors: ['#e7711c'],
    histogram: { lastBucketPercentile: 5 },
    vAxis: { scaleType: 'mirrorLog' },
   type: :histogram,
  height: 400
}
histo_chart = Daru::View::Plot.new(histo_table, histo_options)
histo_chart.show_in_iruby
Out[8]:
In [9]:
histo_options = {
  title: 'Lengths of dinosaurs, in meters',
  colors: ['#e7711c'],
    histogram: { bucketSize: 10000000 },
   type: :histogram,
  height: 400
}
histo_chart = Daru::View::Plot.new(histo_table, histo_options)
histo_chart.show_in_iruby
Out[9]:
In [21]:
tick = Array df_dino_length['Length'].sort.uniq
Out[21]:
[0.9, 1.2, 1.5, 1.8, 2.0, 2.7, 3.4, 4.6, 5.5, 6.1, 7.9, 9.1, 12.2, 15.2, 21.0, 22.9, 27.1, 30.5, 36.6, 45.7]
In [22]:
histo_options = {
  title: 'Lengths of dinosaurs, in meters',
   colors: ['#4285F4'],

    chartArea: { width: 401 },
    hAxis: {
      ticks: tick
    },
    bar: { gap: 0 },

    histogram: {
      bucketSize: 0.02,
      maxNumBuckets: 200,
      minValue: -1,
      maxValue: 1
    },
   type: :histogram,
  height: 400
}
histo_chart = Daru::View::Plot.new(histo_table, histo_options)
histo_chart.show_in_iruby
Out[22]:

Multiple Series

In [27]:
idx = Daru::Index.new ['Quarks', 'Leptons', 'Gauge Bosons', 'Scalar Bosons']
data_rows = [
    [2.0/3, -1, 0, 0],
    [2/3.0, -1, 0, nil],
    [2/3.0, -1, 0, nil],
    [-1.0/3, 0, 1, nil],
    [-1/3.0, 0, -1, nil],
    [-1.0/3, 0, nil, nil],
    [-1.0/3, 0, nil, nil]
  ]
df_subatomic = Daru::DataFrame.rows(data_rows)
df_subatomic.vectors = idx
df_subatomic
Out[27]:
Daru::DataFrame(7x4)
Quarks Leptons Gauge Bosons Scalar Bosons
0 0.6666666666666666 -1 0 0
1 0.6666666666666666 -1 0
2 0.6666666666666666 -1 0
3 -0.3333333333333333 0 1
4 -0.3333333333333333 0 -1
5 -0.3333333333333333 0
6 -0.3333333333333333 0
In [28]:
histo_multiple_options = {
  title: 'Charges of subatomic particles',
    legend: { position: 'top', maxLines: 2 },
    colors: ['#5C3292', '#1A8763', '#871B47', '#999999'],
    interpolateNulls: false,
  type: :histogram,
  height: 400
}
histo_multiple_chart = Daru::View::Plot.new(df_subatomic, histo_multiple_options)
histo_multiple_chart.show_in_iruby
Out[28]: