# 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.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.save_html('scatter.html')```

### Attributes

data[R]
dot_alpha[RW]
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

height[RW]

Total height of Scatterplot

line_median[RW]

Add a line on median of x and y axis

margin_bottom[RW]

Bottom margin

margin_left[RW]

Left margin

margin_right[RW]

Right margin

margin_top[RW]

Top margin

maximum_x[RW]

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

maximum_y[RW]

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

minimum_x[RW]

Minimum 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

name[RW]
v1[R]
v2[R]
width[RW]

Total width of Scatterplot

x_scale[R]
y_scale[R]

### 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```