In [1]:
require 'daru/view'
Out[1]:
In [2]:
Daru::View.plotting_library = :googlecharts
Out[2]:
In [3]:
idx = Daru::Index.new ['Age', 'Weight']
data_rows = [
[ 8, 12],
[ 4, 5.5],
[ 11, 14],
[ 4, 5],
[ 3, 3.5],
[ 6.5, 7]
]
df_age_wt = Daru::DataFrame.rows(data_rows)
df_age_wt.vectors = idx
df_age_wt
Out[3]:
In [4]:
scatter_table = Daru::View::Table.new(df_age_wt, pageSize: 5, height: 200, width: 100)
scatter_table.table
Out[4]:
In [5]:
scatter_options = {
title: 'Age vs. Weight comparison',
hAxis: {title: 'Age', minValue: 0, maxValue: 15},
vAxis: {title: 'Weight', minValue: 0, maxValue: 15},
legend: 'none',
type: :scatter
}
scatter_chart = Daru::View::Plot.new(
scatter_table.table, scatter_options)
scatter_chart.show_in_iruby
Out[5]:
In [6]:
idx = Daru::Index.new ['Hours Studied', 'Final']
data_rows = [
[0, 67], [1, 88], [2, 77],
[3, 93], [4, 85], [5, 91],
[6, 71], [7, 78], [8, 93],
[9, 80], [10, 82],[0, 75],
[5, 80], [3, 90], [1, 72],
[5, 75], [6, 68], [7, 98],
[3, 82], [9, 94], [2, 79],
[2, 95], [2, 86], [3, 67],
[4, 60], [2, 80], [6, 92],
[2, 81], [8, 79], [9, 83],
[3, 75], [1, 80], [3, 71],
[3, 89], [4, 92], [5, 85],
[6, 92], [7, 78], [6, 95],
[3, 81], [0, 64], [4, 85],
[2, 83], [3, 96], [4, 77],
[5, 89], [4, 89], [7, 84],
[4, 92], [9, 98]
]
df_study_hours = Daru::DataFrame.rows(data_rows)
df_study_hours.vectors = idx
df_study_hours
Out[6]:
In [7]:
scatter_material_table = Daru::View::Table.new(df_study_hours, pageSize: 10, height: 300, width: 200)
scatter_material_table.table
Out[7]:
In [8]:
scatter_material_options = {
width: 800,
height: 500,
chart: {
title: 'Students\' Final Grades',
subtitle: 'based on hours studied'
},
hAxis: {title: 'Hours Studied'},
vAxis: {title: 'Grade'},
type: :scatter
}
scatter_material_chart = Daru::View::Plot.new(
scatter_material_table.table, scatter_material_options)
scatter_material_chart.show_in_iruby
Out[8]:
In [9]:
idx = Daru::Index.new ['Student ID', 'Hours Studied', 'Final']
data_rows = [
[0, 0, 67], [1, 1, 88], [2, 2, 77],
[3, 3, 93], [4, 4, 85], [5, 5, 91],
[6, 6, 71], [7, 7, 78], [8, 8, 93],
[9, 9, 80], [10, 10, 82], [11, 0, 75],
[12, 5, 80], [13, 3, 90], [14, 1, 72],
[15, 5, 75], [16, 6, 68], [17, 7, 98],
[18, 3, 82], [19, 9, 94], [20, 2, 79],
[21, 2, 95], [22, 2, 86], [23, 3, 67],
[24, 4, 60], [25, 2, 80], [26, 6, 92],
[27, 2, 81], [28, 8, 79], [29, 9, 83]
]
df_id_study_hours = Daru::DataFrame.rows(data_rows)
df_id_study_hours.vectors = idx
df_id_study_hours
Out[9]:
In [10]:
scatter_dualY_table = Daru::View::Table.new(df_id_study_hours, pageSize: 10, height: 300, width: 300)
scatter_dualY_table.table
Out[10]:
In [11]:
scatter_dualY_options = {
chart: {
title: 'Students\' Final Grades',
subtitle: 'based on hours studied'
},
width: 800,
height: 500,
# FixMe: There is some problem in below code execution. So similar charts
# options is not working from this
# link : https://developers.google.com/chart/interactive/docs/gallery/scatterchart#fullhtml
# series: {
# '0': {axis: 'hours studied'},
# '1': {axis: 'final grade'}
# },
# axes: {
# y: {
# 'hours studied': {label: 'Hours Studied'},
# 'final grade': {label: 'Final Exam Grade'}
# }
# },
type: :scatter
}
scatter_dualY_chart = Daru::View::Plot.new(
scatter_dualY_table.table, scatter_dualY_options)
scatter_dualY_chart.show_in_iruby
Out[11]:
TODO: Other examples from this link: https://developers.google.com/chart/interactive/docs/gallery/scatterchart#fullhtml
In [ ]: