/
monthseries.rb
executable file
·42 lines (38 loc) · 1.57 KB
/
monthseries.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env ruby
require 'swineherd'
require 'swineherd/script/r_script' ; include Swineherd::Script
#
# Often it is the case you've got timeseries of the form:
#
# 201006 1234
# 201007 5678
# ...
#
# This transforms the month field into something R can understand and plots it
# with the right scaling.
#
Settings.define :width, :default => 1200, :description => "Plot width in pixels"
Settings.define :month, :default => 1, :description => "Column to use as the month field"
Settings.define :y, :default => 2, :description => "Column to use as y values"
Settings.define :points, :default => false, :description => "Plot defaults to line, use points instead"
Settings.define :xlab, :default => "X", :description => "X label"
Settings.define :ylab, :default => "Y", :description => "Y label"
Settings.define :point_size, :default => 1, :description => "Width of line in pixels or size of points in pixels"
Settings.define :title, :default => "", :description => "Title of the plot"
Settings.resolve!
raise "No input data!" unless Settings.rest.first
plotter = RScript.new('templates/monthseries.R.erb')
plotter.output << File.basename(Settings.rest.first).gsub(File.extname(Settings.rest.first), ".png")
plotter.attributes = {
:data => Settings.rest.first,
:plot => plotter.output,
:month => Settings.month,
:y => Settings.y,
:xlab => Settings.xlab,
:ylab => Settings.ylab,
:width => Settings.width,
:size => Settings.point_size,
:title => Settings.title,
:points => Settings.points
}
plotter.run true