module R::PNG
Public Class Methods
Source
# File lib/rbbt/util/R/plot.rb, line 173 def self.eog(data, script = nil, width = nil, height = nil, options = {}) TmpFile.with_file :extension => 'png' do |filename| ggplot(filename, data, script, width, height, options) `eog #{ filename }` end end
Source
# File lib/rbbt/util/R/plot.rb, line 180 def self.eog_plot(data, script = nil, width = nil, height = nil, options = {}) TmpFile.with_file :extension => 'png' do |filename| plot(filename, data, script, width, height, options) `eog #{ filename }` end end
Source
# File lib/rbbt/util/R/plot.rb, line 191 def self.ggplot(filename, data, script = nil, width = nil, height = nil, options = {}) width ||= 3 height ||= 3 values = [] sources = [:plot, options[:source]].flatten.compact field_classes = R.field_classes(data) if field_classes.nil? options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')' data.R <<-EOF, :plot, options rbbt.require('ggplot2') plot = { #{script} } ggsave('#{filename}', plot, width = #{R.ruby2R width}, height = #{R.ruby2R height}) data = NULL EOF end
Source
# File lib/rbbt/util/R/plot.rb, line 187 def self.ggplotPNG(*args) ggplot(*args) end
Source
# File lib/rbbt/util/R/plot.rb, line 211 def self.plot(filename, data = nil, script = nil, width = nil, height = nil, options = {}, &block) width ||= 600 height ||= 600 values = [] script ||= "" if block_given? s = StringIO.new class << s def method_missing(name, *args) name = name.to_s if name[-1] == '=' arg = args.first value = if String === arg arg else R.ruby2R arg end add("" << name[0..-2] << "=" << value) else args_strs = [] args.each do |arg| value = if String === arg arg else R.ruby2R arg end args_strs << value end add("" << name << "(" << args_strs * ", " << ")") end end def add(line) self.write line << "\n" end end block.call(s) s.rewind script << "\n" << s.read end sources = [:plot, options[:source]].flatten.compact if data field_classes = R.field_classes(data) if field_classes.nil? options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')' if field_classes.any? data.R <<-EOF, :plot, options rbbt.png_plot("#{ filename }", width=#{ width }, height = #{ height }, function(){ #{script} }) data = NULL EOF else R.run <<-EOF, :plot, options rbbt.png_plot("#{ filename }", width=#{ width }, height = #{ height }, function(){ #{script} }) EOF end end