Scatterplot with statsample

Creating a scatterplot with statsample's Statsample::Graph::Scatterplot class.

In this example we'll demonstrate how a normally distributed Daru::Vector can be created using the daru and distribution gems, and how the values generated can be plotted very easily using the 'scatterplot' shorthand and supplying X and Y co-ordinates.

Statsample uses rubyvis internally for generating plots.


In [1]:
require 'statsample'
include Statsample::Shorthand

n = 100
x = rnorm(n)
y = x + rnorm(n,0.5,0.2)
Statsample::Graph::Scatterplot.new(x,y)


Out[1]:
−3.0−2.5−2.0−1.5−1.0−0.50.51.01.52.02.50.51.01.52.0

In [ ]: