Class: Rust::Plots::BasePlot
Overview
Represents a generic plot in R.
Direct Known Subclasses
Instance Method Summary collapse
-
#[]=(option, value) ⇒ Object
Sets any R
optionwith the givenvalue. - #_add_renderable(renderable) ⇒ Object
- #_do_not_override_options! ⇒ Object
-
#axis(axis) ⇒ Object
Adds an
axisto show instead of the default ones. -
#color(color) ⇒ Object
Sets the
colorof the plot. -
#grid(grid) ⇒ Object
Shows the given
grid. -
#initialize ⇒ BasePlot
constructor
Creates a new base plot object.
-
#palette(size) ⇒ Object
Returns a color palette of the given
size. -
#pdf(path, **options) ⇒ Object
Prints the plot on a PDF file at path.
-
#show ⇒ Object
Shows the plot in a window.
-
#title(title) ⇒ Object
Sets the
titleof the plot. -
#x_label(label) ⇒ Object
Sets the x-axis label.
-
#x_range(range) ⇒ Object
(also: #xlim)
Sets the limits for the x-axis.
-
#y_label(label) ⇒ Object
Sets the y-axis label.
-
#y_range(range) ⇒ Object
(also: #ylim)
Sets the limits for the y-axis.
Constructor Details
#initialize ⇒ BasePlot
Creates a new base plot object.
16 17 18 19 20 |
# File 'lib/rust/plots/core.rb', line 16 def initialize @renderables = [] = Rust::Options.new = true end |
Instance Method Details
#[]=(option, value) ⇒ Object
Sets any R option with the given value.
120 121 122 |
# File 'lib/rust/plots/core.rb', line 120 def []=(option, value) [option.to_s] = value end |
#_add_renderable(renderable) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/rust/plots/core.rb', line 110 def _add_renderable(renderable) raise TypeError, "Expected Renderable" unless renderable.is_a?(Renderable) @renderables << renderable return self end |
#_do_not_override_options! ⇒ Object
124 125 126 |
# File 'lib/rust/plots/core.rb', line 124 def = false end |
#axis(axis) ⇒ Object
Adds an axis to show instead of the default ones.
74 75 76 77 78 79 80 81 |
# File 'lib/rust/plots/core.rb', line 74 def axis(axis) ['xaxt'] = 'n' ['yaxt'] = 'n' self._add_renderable(axis) return self end |
#color(color) ⇒ Object
Sets the color of the plot.
104 105 106 107 108 |
# File 'lib/rust/plots/core.rb', line 104 def color(color) ['col'] = color return self end |
#grid(grid) ⇒ Object
Shows the given grid.
86 87 88 89 90 |
# File 'lib/rust/plots/core.rb', line 86 def grid(grid) self._add_renderable(grid) return self end |
#palette(size) ⇒ Object
Returns a color palette of the given size.
43 44 45 46 47 48 49 |
# File 'lib/rust/plots/core.rb', line 43 def palette(size) if size <= 1 return ['black'] else return Rust._pull("hcl.colors(n=#{size})") end end |
#pdf(path, **options) ⇒ Object
Prints the plot on a PDF file at path. options can be specified for the PDF (e.g., width and height).
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rust/plots/core.rb', line 143 def pdf(path, **) pdf_function = Rust::Function.new("pdf") pdf_function. = Rust::Options.from_hash() pdf_function.['file'] = path Rust.exclusive do pdf_function.call self._show self._render_others Rust._eval("dev.off()") end return self end |
#show ⇒ Object
Shows the plot in a window.
131 132 133 134 135 136 137 138 |
# File 'lib/rust/plots/core.rb', line 131 def show() Rust.exclusive do self._show self._render_others end return self end |
#title(title) ⇒ Object
Sets the title of the plot.
95 96 97 98 99 |
# File 'lib/rust/plots/core.rb', line 95 def title(title) ['main'] = title return self end |
#x_label(label) ⇒ Object
Sets the x-axis label.
25 26 27 28 29 |
# File 'lib/rust/plots/core.rb', line 25 def x_label(label) ['xlab'] = label return self end |
#x_range(range) ⇒ Object Also known as: xlim
Sets the limits for the x-axis.
54 55 56 57 58 |
# File 'lib/rust/plots/core.rb', line 54 def x_range(range) ['xlim'] = range return self end |
#y_label(label) ⇒ Object
Sets the y-axis label.
34 35 36 37 38 |
# File 'lib/rust/plots/core.rb', line 34 def y_label(label) ['ylab'] = label return self end |
#y_range(range) ⇒ Object Also known as: ylim
Sets the limits for the y-axis.
64 65 66 67 68 |
# File 'lib/rust/plots/core.rb', line 64 def y_range(range) ['ylim'] = range return self end |