This notebook describes plots that can be drawn using Gruff in Daru.

Lets change the plotting library to Gruff.

In [1]:
require 'daru'
Daru.plotting_library = :gruff
Out[1]:
:gruff

Line Graph

In [3]:
df = Daru::DataFrame.new({
  a: [1, 3, 5, 7, 5, 0],
  b: [1, 5, 2, 5, 1, 0],
  c: [1, 6, 7, 2, 6, 0]
  }, index: 'a'..'f')
df.plot type: :line
Out[3]:

One can also select specific columns to display on x and y axis.

In [4]:
df.plot type: :line, x: :a, y: [:b, :c]
Out[4]:

Scatter Plot

In [5]:
df.plot type: :scatter, x: :a, y: :b
Out[5]:

Bar Graph

In [6]:
df.plot type: :bar
Out[6]:

Categorical Data Visualization

Scatter plot can be differentiated by a category vector.

In [7]:
df = Daru::DataFrame.new({
  a: [1, 2, 3, 4, 5],
  b: [3, 2, 5, 1, 5],
  c: [:a, :a, :a, :b, :b]
  })
df.to_category :c
Out[7]:
Daru::DataFrame(5x3)
a b c
0 1 3 a
1 2 2 a
2 3 5 a
3 4 1 b
4 5 5 b
In [8]:
df.plot type: :scatter, x: :a, y: :b, categorized: {by: :c}
Out[8]: