Parent

Methods

Included Modules

Class/Module Index [+]

Quicksearch

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.[2] 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

name[RW]
width[RW]

Total width of Scatterplot

height[RW]

Total height of Scatterplot

dot_alpha[RW]
line_median[RW]

Add a line on median of x and y axis

margin_top[RW]

Top margin

margin_bottom[RW]

Bottom margin

margin_left[RW]

Left margin

margin_right[RW]

Right margin

data[R]
v1[R]
v2[R]
groups[RW]

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

x_scale[R]
y_scale[R]
minimum_x[RW]

Minimum value on x axis. Calculated automaticly from data if not set

maximum_x[RW]

Maximum value on x axis. Calculated automaticly from data if not set

minimum_y[RW]

Minimum value on y axis. Set to 0 if not set

maximum_y[RW]

Maximum value on y axis. Calculated automaticly from data if not set.

Public Class Methods

new(v1,v2,opts=Hash.new) click to toggle source

Create a new Scatterplot. Params:

# 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

to_svg() click to toggle source

Returns SVG with scatterplot

# File lib/statsample/graph/scatterplot.rb, line 199
def to_svg
  rp=rubyvis_panel
  rp.render
  rp.to_svg
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.