require 'daru/view' Daru::View.plotting_library = :nyaplot dv = Daru::Vector.new [:a, :a, :a, :b, :b, :c], type: :category bar_graph1 = Daru::View::Plot.new(dv, type: :bar) bar_graph1.chart.class bar_graph1.show_in_iruby dv = Daru::Vector.new ['III']*10 + ['II']*5 + ['I']*5, type: :category, categories: ['I', 'II', 'III'] dv.type bar_graph2 = Daru::View::Plot.new(dv, type: :bar) bar_graph2.class bar_graph2.chart.class # Nyaplot methods will work.Since #chart is Nyaplot::Plot class object bar_graph2.chart.x_label 'Cat' bar_graph2.chart.y_label 'Frequency' bar_graph2.chart # or bar_graph2.show_in_iruby bar_graph2_per = Daru::View::Plot.new(dv, type: :bar, method: :percentage) bar_graph2_per.chart.x_label 'Categories' bar_graph2_per.chart.y_label 'Percentage (%)' bar_graph2_per.show_in_iruby bar_graph2_frac = Daru::View::Plot.new(dv, type: :bar, method: :fraction) # bar_graph2_frac.chart.x_label 'Categories' bar_graph2_frac.chart.y_label 'Fraction' bar_graph2_frac.show_in_iruby df = Daru::DataFrame.new({ a: [1, 2, 4, -2, 5, 23, 0], b: [3, 1, 3, -6, 2, 1, 0], c: ['I', 'II', 'I', 'III', 'I', 'III', 'II'] }) df.to_category :c df[:c].type bar_graph3 = Daru::View::Plot.new(df, type: :bar, x: :c) bar_graph3.show_in_iruby df = Daru::DataFrame.new({ a: [1, 2, 4, -2, 5, 23, 0], b: [3, 1, 3, -6, 2, 1, 0], c: ['I', 'II', 'I', 'III', 'I', 'III', 'II'] }) df.to_category :c df[:c].type scatter_1 = Daru::View::Plot.new(df, type: :scatter, x: :a, y: :b, categorized: {by: :c, method: :color}) scatter_1.show_in_iruby scatter_1.chart.xrange [-10, 10] scatter_1.chart.yrange [-10, 10] scatter_2 = Daru::View::Plot.new(df, type: :scatter, x: :a, y: :b, categorized: {by: :c, method: :shape}) scatter_2.show_in_iruby scatter_2.chart.xrange [-10, 10] scatter_2.chart.yrange [-10, 10] scatter_3 = Daru::View::Plot.new(df, type: :scatter, x: :a, y: :b, categorized: {by: :c, method: :color, color: [:red, :blue, :green]}) scatter_3.show_in_iruby scatter_2.chart.xrange [-10, 10] scatter_2.chart.yrange [-10, 10] scatter_4 = Daru::View::Plot.new(df, type: :scatter, x: :a, y: :b, categorized: {by: :c, method: :size, size: [300, 600, 900]}) scatter_4.show_in_iruby scatter_4.chart.xrange [-10, 10] scatter_4.chart.yrange [-10, 10] df = Daru::DataFrame.new({ a: [1, 2, 3, 4, 5, 6, 7, 8, 9], b: [2, 4, 6, 1, 3, 5, 6, 4, 3], c: ['I']*3 + ['II']*3 + ['III']*3 }) df.to_category :c df[:c].type line_1 = Daru::View::Plot.new(df, type: :line, x: :a, y: :b, categorized: {by: :c, method: :color}) line_1.show_in_iruby line_2 = Daru::View::Plot.new(df, type: :line, x: :a, y: :b, categorized: {by: :c, method: :stroke_width}) line_2.show_in_iruby line_2.chart.xrange [-10, 10] line_2.chart.yrange [-10, 10]