Class: Rust::Plots::GGPlot::PlotBuilder
- Defined in:
- lib/rust/external/ggplot2/plot_builder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #draw_bars(**options) ⇒ Object
- #draw_boxplot(**options) ⇒ Object
- #draw_cols(**options) ⇒ Object
- #draw_density(**options) ⇒ Object
- #draw_histogram(**options) ⇒ Object
- #draw_lines(**options) ⇒ Object
- #draw_points(**options) ⇒ Object
- #flip_coordinates ⇒ Object
-
#initialize(data = nil) ⇒ PlotBuilder
constructor
A new instance of PlotBuilder.
- #labeled(value) ⇒ Object
- #with_color(variable) ⇒ Object
- #with_color_label(value) ⇒ Object
- #with_fill(variable) ⇒ Object
- #with_group(variable) ⇒ Object
- #with_theme(theme) ⇒ Object
- #with_title(value) ⇒ Object
- #with_x(variable, label = nil) ⇒ Object
- #with_x_label(value) ⇒ Object
- #with_y(variable) ⇒ Object
- #with_y_label(value) ⇒ Object
Constructor Details
#initialize(data = nil) ⇒ PlotBuilder
Returns a new instance of PlotBuilder.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 11 def initialize(data=nil) @data = data @aes_options = {} @label_options = {} @current_context = :title @layers = [] end |
Class Method Details
.for_dataframe(data_frame) ⇒ Object
7 8 9 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 7 def self.for_dataframe(data_frame) return PlotBuilder.new(data_frame) end |
Instance Method Details
#build ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 171 def build plot = Plot.new(@data, Aes.new(**@aes_options)) plot.theme = @theme if @theme plot << @layers if @layers.size > 0 if @label_options.size > 0 if @label_options.keys.include?(:group) value = @label_options.delete(:group) selected = [:x, :y] - @label_options.keys @label_options[selected.first] = value if selected.size == 1 end plot << Labels.new(**@label_options) end return plot end |
#draw_bars(**options) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 115 def (**) @layers << GeomBar.new(**) @current_context = nil return self end |
#draw_boxplot(**options) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 131 def draw_boxplot(**) @layers << GeomBoxplot.new(**) @current_context = nil return self end |
#draw_cols(**options) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 123 def draw_cols(**) @layers << GeomCol.new(**) @current_context = nil return self end |
#draw_density(**options) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 147 def draw_density(**) @layers << GeomDensity.new(**) @current_context = nil return self end |
#draw_histogram(**options) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 139 def draw_histogram(**) @layers << GeomHistogram.new(**) @current_context = nil return self end |
#draw_lines(**options) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 107 def draw_lines(**) @layers << GeomLine.new(**) @current_context = nil return self end |
#draw_points(**options) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 99 def draw_points(**) @layers << GeomPoint.new(**) @current_context = nil return self end |
#flip_coordinates ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 163 def flip_coordinates @layers << FlipCoordinates.new @current_context = nil return self end |
#labeled(value) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 67 def labeled(value) raise "No context for assigning a label" unless @current_context @label_options[@current_context] = value @current_context = nil return self end |
#with_color(variable) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 49 def with_color(variable) variable = variable.to_sym if variable.is_a?(String) @aes_options[:color] = variable @current_context = :color return self end |
#with_color_label(value) ⇒ Object
87 88 89 90 91 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 87 def with_color_label(value) @label_options[:color] = value return self end |
#with_fill(variable) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 58 def with_fill(variable) variable = variable.to_sym if variable.is_a?(String) @aes_options[:fill] = variable @current_context = :fill return self end |
#with_group(variable) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 40 def with_group(variable) variable = variable.to_sym if variable.is_a?(String) @aes_options[:group] = variable @current_context = :group return self end |
#with_theme(theme) ⇒ Object
155 156 157 158 159 160 161 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 155 def with_theme(theme) @layers << theme @current_context = nil return self end |
#with_title(value) ⇒ Object
93 94 95 96 97 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 93 def with_title(value) @label_options[:title] = value return self end |
#with_x(variable, label = nil) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 22 def with_x(variable, label = nil) variable = variable.to_sym if variable.is_a?(String) @aes_options[:x] = variable @current_context = :x return self end |
#with_x_label(value) ⇒ Object
75 76 77 78 79 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 75 def with_x_label(value) @label_options[:x] = value return self end |
#with_y(variable) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 31 def with_y(variable) variable = variable.to_sym if variable.is_a?(String) @aes_options[:y] = variable @current_context = :y return self end |
#with_y_label(value) ⇒ Object
81 82 83 84 85 |
# File 'lib/rust/external/ggplot2/plot_builder.rb', line 81 def with_y_label(value) @label_options[:y] = value return self end |