Skip to content

Instantly share code, notes, and snippets.

@phosphene
Created May 2, 2010 16:25
Show Gist options
  • Save phosphene/387258 to your computer and use it in GitHub Desktop.
Save phosphene/387258 to your computer and use it in GitHub Desktop.
require 'rsruby'
r = RSRuby.instance
# mod of Peter Lane's Ruby for Scientific Research plot example
# construct data to plot, graph of x vs exp(x)
xs = 10.times.collect {|i| i}
ys = xs.collect {|x| r.exp(x)}
r.png("exp_example.png") # tell R we will create png file
r.plot(:x => xs,
:y => ys, # (x,y) coordinates to plot
:type=> "o", # draw a line through points
:col=> "blue", # colour the line blue
:main=> "Plot of x against exp(x)", # add title to graph
:xlab => "x", :ylab => "exp(x)") # add labels to axes
r.eval_R("dev.off()") # finish the plotting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment