class Statsample::Graph::Scatterplot
Scatterplot¶ ↑
From Wikipedia: A scatter plot or scattergraph is a type of mathematical diagram using Cartesian coordinates to display values for two variables for a set of data.
The data is displayed as a collection of points, each having the value of one variable determining the position on the horizontal axis and the value of the other variable determining the position on the vertical axis. This kind of plot is also called a scatter chart, scatter diagram and scatter graph.
Usage¶ ↑
Svg output¶ ↑
a=[1,2,3,4].to_scale b=[3,4,5,6].to_scale puts Statsample::Graph::Scatterplot.new(a,b).to_svg
Using ReportBuilder¶ ↑
a=[1,2,3,4].to_scale b=[3,4,5,6].to_scale rb=ReportBuilder.new rb.add(Statsample::Graph::Scatterplot.new(a,b)) rb.save_html('scatter.html')
Scatterplot¶ ↑
From Wikipedia: A scatter plot or scattergraph is a type of mathematical diagram using Cartesian coordinates to display values for two variables for a set of data.
The data is displayed as a collection of points, each having the value of one variable determining the position on the horizontal axis and the value of the other variable determining the position on the vertical axis. This kind of plot is also called a scatter chart, scatter diagram and scatter graph.
Usage¶ ↑
Svg output¶ ↑
a=[1,2,3,4].to_scale b=[3,4,5,6].to_scale puts Statsample::Graph::Scatterplot.new(a,b).to_svg
Using ReportBuilder¶ ↑
a=[1,2,3,4].to_scale b=[3,4,5,6].to_scale rb=ReportBuilder.new rb.add(Statsample::Graph::Scatterplot.new(a,b)) rb.save_html('scatter.html')
Attributes
Array with assignation to groups of bars For example, for four vectors,
boxplot.groups=[1,2,1,3]
Assign same color to first and third element, and different to second and fourth
Total height of Scatterplot
Add a line on median of x and y axis
Bottom margin
Left margin
Right margin
Top margin
Maximum value on x axis. Calculated automaticly from data if not set
Maximum value on y axis. Calculated automaticly from data if not set.
Minimum value on x axis. Calculated automaticly from data if not set
Minimum value on y axis. Set to 0 if not set
Total width of Scatterplot
Public Class Methods
Create a new Scatterplot. Params:
-
v1: Vector on X axis
-
v2: Vector on Y axis
-
opts: Hash of options. See attributes of Scatterplot
# File lib/statsample/graph/scatterplot.rb, line 68 def initialize(v1,v2,opts=Hash.new) @v1_name,@v2_name = v1.name,v2.name @v1,@v2 = Statsample.only_valid_clone(v1,v2) opts_default={ :name=>_("Scatterplot (%s - %s)") % [@v1_name, @v2_name], :width=>400, :height=>300, :dot_alpha=>0.5, :line_median=>false, :margin_top=>10, :margin_bottom=>20, :margin_left=>20, :margin_right=>20, :minimum_x=>nil, :maximum_x=>nil, :minimum_y=>nil, :maximum_y=>nil, :groups=>nil } @opts=opts_default.merge(opts) opts_default.keys.each {|k| send("#{k}=", @opts[k]) } @data=[] @v1.each_with_index {|d1,i| @data.push({:x=>d1, :y=>@v2[i]}) } end
Public Instance Methods
Returns SVG with scatterplot
# File lib/statsample/graph/scatterplot.rb, line 199 def to_svg rp=rubyvis_panel rp.render rp.to_svg end