galaaz 2.1.7 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +63 -58
- data/blogs/galaaz_ggplot/galaaz_ggplot.log +59 -68
- data/blogs/galaaz_ggplot/galaaz_ggplot.md +91 -84
- data/blogs/galaaz_ggplot/galaaz_ggplot.tex +125 -94
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/midwest_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/scatter_plot_rb.png +0 -0
- data/blogs/gknit/gknit.Rmd +33 -28
- data/blogs/gknit/gknit.md +47 -42
- data/blogs/gknit/gknit.tex +1368 -0
- data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
- data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
- data/blogs/gknit/gknit_files/figure-latex/bubble-1.png +0 -0
- data/blogs/gknit/gknit_files/gknit_files/figure-latex/bubble-1.png +0 -0
- data/blogs/manual/manual.Rmd +129 -60
- data/blogs/manual/manual.log +289 -545
- data/blogs/manual/manual.md +551 -467
- data/blogs/manual/manual.tex +1059 -485
- data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
- data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
- data/blogs/manual/manual_files/figure-markdown_github/bubble-1.png +0 -0
- data/blogs/manual/manual_files/figure-markdown_github/diverging_bar.png +0 -0
- data/blogs/manual/manual_files/manual_files/figure-latex/bubble-1.png +0 -0
- data/blogs/nse_dplyr/nse_dplyr.Rmd +28 -7
- data/blogs/nse_dplyr/nse_dplyr.log +49 -153
- data/blogs/nse_dplyr/nse_dplyr.md +676 -705
- data/blogs/nse_dplyr/nse_dplyr.tex +1589 -0
- data/blogs/oh_my/oh_my.Rmd +193 -55
- data/blogs/oh_my/oh_my.log +265 -95
- data/blogs/oh_my/oh_my.md +236 -95
- data/blogs/oh_my/oh_my.tex +1976 -68
- data/blogs/ruby_plot/ruby_plot.Rmd +42 -34
- data/blogs/ruby_plot/ruby_plot.log +101 -99
- data/blogs/ruby_plot/ruby_plot.md +52 -46
- data/blogs/ruby_plot/ruby_plot.tex +134 -102
- data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/dose_len.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/dose_len.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
- data/lib/galaaz/cli.rb +51 -10
- data/script/omarchy/README.md +1 -1
- data/script/omarchy/galaaz-guide.sh +1 -1
- data/sty/galaaz.sty +22 -0
- data/version.rb +1 -1
- metadata +19 -1
|
@@ -5,15 +5,16 @@ language, with a large community, a very large set of libraries and
|
|
|
5
5
|
great for web development. However, it lacks libraries for data science,
|
|
6
6
|
statistics, scientific plotting and machine learning. On the other hand,
|
|
7
7
|
R is considered one of the most powerful languages for solving all of
|
|
8
|
-
the above problems.
|
|
9
|
-
|
|
8
|
+
the above problems. **Python** is a strong competitor: NumPy, pandas,
|
|
9
|
+
SciPy, and scikit-learn are widely used examples among **many
|
|
10
|
+
thousands** of packages on PyPI for numerical and ML work.
|
|
10
11
|
|
|
11
12
|
With Galaaz we do not intend to re-implement any of the scientific
|
|
12
13
|
libraries in R; we allow for very tight coupling between the two
|
|
13
14
|
languages to the point that the Ruby developer does not need to think
|
|
14
15
|
about R syntax for every call. **Galaaz 2.0** does this with
|
|
15
|
-
**[JRuby](https://www.jruby.org/)** or **CRuby** and **GNU R**: a
|
|
16
|
-
evaluates R from Ruby and exchanges data between processes.
|
|
16
|
+
**[JRuby](https://www.jruby.org/)** or **CRuby** and **GNU R**: a
|
|
17
|
+
**bridge** evaluates R from Ruby and exchanges data between processes.
|
|
17
18
|
|
|
18
19
|
An **earlier** Galaaz prototype used Oracle’s **GraalVM** with
|
|
19
20
|
**TruffleRuby** and **FastR** in one JVM. That stack is **historical**;
|
|
@@ -56,9 +57,9 @@ but could be installed prior to the demo if desired:
|
|
|
56
57
|
- ggplot2
|
|
57
58
|
- gridExtra
|
|
58
59
|
|
|
59
|
-
Installation of R packages requires a development environment.
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
Installation of R packages requires a development environment. On Linux,
|
|
61
|
+
a typical build toolchain (GCC, headers) is usually enough. On macOS,
|
|
62
|
+
Apple’s **Xcode Command Line Tools** are commonly required.
|
|
62
63
|
|
|
63
64
|
In order to run the ‘specs’ the following Ruby package is necessary:
|
|
64
65
|
|
|
@@ -70,33 +71,32 @@ In order to run the ‘specs’ the following Ruby package is necessary:
|
|
|
70
71
|
|
|
71
72
|
## Running the demo
|
|
72
73
|
|
|
73
|
-
The ggplot for this
|
|
74
|
+
The ggplot examples for this demo were adapted from:
|
|
74
75
|
<http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html>.
|
|
75
76
|
|
|
76
|
-
|
|
77
|
+
At the shell, from a suitable Galaaz environment:
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
galaaz master_list:scatter_plot
|
|
79
80
|
|
|
80
81
|
## Running other demos
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
Running
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
galaaz -T
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
do be available. To install ‘rspec’ just do ‘gem install rspec’.
|
|
87
|
+
lists available demo tasks. To run a demo, use **`galaaz`** where you
|
|
88
|
+
would otherwise invoke **`rake`**. For example, if the list shows
|
|
89
|
+
`rake sthda:bar`, run `galaaz sthda:bar`. To run every demo in the
|
|
90
|
+
**sthda** category, use `galaaz sthda:all`. Some examples require
|
|
91
|
+
**rspec**; install it with `gem install rspec`.
|
|
92
92
|
|
|
93
93
|
# The demo code
|
|
94
94
|
|
|
95
95
|
The following is the Ruby code and plot for the above example. There is
|
|
96
|
-
a small difference between the code in the example and the code
|
|
97
|
-
If the example is
|
|
98
|
-
generate an
|
|
99
|
-
|
|
96
|
+
a small difference between the code in the example and the code below.
|
|
97
|
+
If the example is **run**, the plot will appear on the screen; below, we
|
|
98
|
+
generate an SVG image and then include it in this document. In order to
|
|
99
|
+
generate and image, the R.svg device is used. To generate the plot on
|
|
100
100
|
the screen, use the R.awt device, as commented on the code.
|
|
101
101
|
|
|
102
102
|
``` ruby
|
|
@@ -192,38 +192,43 @@ notation and the preferred color is blue.
|
|
|
192
192
|
``` ruby
|
|
193
193
|
# corp_theme.rb
|
|
194
194
|
# defines the corporate theme for all plots
|
|
195
|
-
|
|
195
|
+
|
|
196
196
|
module CorpTheme
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
#
|
|
200
|
-
#
|
|
201
|
-
|
|
202
|
-
|
|
198
|
+
# ---------------------------------------------------------------
|
|
199
|
+
# Plot theme: no major/minor grids, borders, or background;
|
|
200
|
+
# turn off scientific notation.
|
|
201
|
+
# ---------------------------------------------------------------
|
|
202
|
+
|
|
203
203
|
def self.global_theme
|
|
204
|
-
|
|
204
|
+
|
|
205
205
|
R.options(scipen: 999) # turn-off scientific notation like 1e+48
|
|
206
|
-
|
|
206
|
+
|
|
207
207
|
# remove major grids
|
|
208
|
-
global_theme =
|
|
208
|
+
global_theme =
|
|
209
|
+
R.theme(panel__grid__major: E.element_blank())
|
|
209
210
|
# remove minor grids
|
|
210
|
-
global_theme = global_theme +
|
|
211
|
+
global_theme = global_theme +
|
|
212
|
+
R.theme(panel__grid__minor: E.element_blank)
|
|
211
213
|
# remove border
|
|
212
|
-
global_theme = global_theme +
|
|
214
|
+
global_theme = global_theme +
|
|
215
|
+
R.theme(panel__border: E.element_blank)
|
|
213
216
|
# remove background
|
|
214
|
-
global_theme = global_theme +
|
|
217
|
+
global_theme = global_theme +
|
|
218
|
+
R.theme(panel__background: E.element_blank)
|
|
215
219
|
# Change axis font
|
|
216
220
|
global_theme = global_theme +
|
|
217
|
-
|
|
221
|
+
R.theme(axis__text: E.element_text(
|
|
222
|
+
size: 8, color: "#000080"))
|
|
218
223
|
# change color of axis titles
|
|
219
224
|
global_theme = global_theme +
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
+
R.theme(axis__title: E.element_text(
|
|
226
|
+
color: "#000080",
|
|
227
|
+
face: "bold",
|
|
228
|
+
size: 8,
|
|
229
|
+
hjust: 1))
|
|
225
230
|
end
|
|
226
|
-
|
|
231
|
+
|
|
227
232
|
end
|
|
228
233
|
```
|
|
229
234
|
|
|
@@ -232,7 +237,7 @@ We now define a ScatterPlot class:
|
|
|
232
237
|
``` ruby
|
|
233
238
|
# ScatterPlot.rb
|
|
234
239
|
# creates a scatter plot and allow some configuration
|
|
235
|
-
|
|
240
|
+
|
|
236
241
|
class ScatterPlot
|
|
237
242
|
|
|
238
243
|
attr_accessor :title
|
|
@@ -240,55 +245,55 @@ class ScatterPlot
|
|
|
240
245
|
attr_accessor :caption
|
|
241
246
|
attr_accessor :x_label
|
|
242
247
|
attr_accessor :y_label
|
|
243
|
-
|
|
244
|
-
|
|
248
|
+
|
|
249
|
+
# ---------------------------------------------------------------
|
|
245
250
|
# Initialize the plot with the data and the x and y variables
|
|
246
|
-
|
|
251
|
+
# ---------------------------------------------------------------
|
|
247
252
|
|
|
248
253
|
def initialize(data, x:, y:)
|
|
249
254
|
@data = data
|
|
250
255
|
@x = x
|
|
251
256
|
@y = y
|
|
252
257
|
end
|
|
253
|
-
|
|
254
|
-
|
|
258
|
+
|
|
259
|
+
# ---------------------------------------------------------------
|
|
255
260
|
# Define groupings by color and size
|
|
256
|
-
|
|
261
|
+
# ---------------------------------------------------------------
|
|
257
262
|
|
|
258
263
|
def group_by(color:, size:)
|
|
259
264
|
@color_by = color
|
|
260
265
|
@size_by = size
|
|
261
266
|
end
|
|
262
267
|
|
|
263
|
-
|
|
264
|
-
# Add a smoothing line
|
|
265
|
-
#
|
|
266
|
-
#---------------------------------------------------------------------------------
|
|
268
|
+
# ---------------------------------------------------------------
|
|
269
|
+
# Add a smoothing line; confidence: true draws a CI band.
|
|
270
|
+
# ---------------------------------------------------------------
|
|
267
271
|
|
|
268
272
|
def add_smoothing_line(method:, confidence: true)
|
|
269
273
|
@method = method
|
|
270
274
|
@confidence = confidence
|
|
271
275
|
end
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
#
|
|
275
|
-
# @param title [String]
|
|
276
|
-
# @return
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
def graph_params(title: "", subtitle: "", caption: "",
|
|
276
|
+
|
|
277
|
+
# ---------------------------------------------------------------
|
|
278
|
+
# Graph title / labels, formatted for this theme.
|
|
279
|
+
# @param title [String] title to add to the graph
|
|
280
|
+
# @return labs() result that can be included in a graph
|
|
281
|
+
# ---------------------------------------------------------------
|
|
282
|
+
|
|
283
|
+
def graph_params(title: "", subtitle: "", caption: "",
|
|
284
|
+
x_label: "", y_label: "")
|
|
280
285
|
R.labs(
|
|
281
|
-
title: title,
|
|
282
|
-
subtitle: subtitle,
|
|
286
|
+
title: title,
|
|
287
|
+
subtitle: subtitle,
|
|
283
288
|
caption: caption,
|
|
284
|
-
y_label: y_label,
|
|
285
|
-
x_label: x_label,
|
|
289
|
+
y_label: y_label,
|
|
290
|
+
x_label: x_label,
|
|
286
291
|
)
|
|
287
292
|
end
|
|
288
293
|
|
|
289
|
-
|
|
294
|
+
# ---------------------------------------------------------------
|
|
290
295
|
# Prepare the plot's points
|
|
291
|
-
|
|
296
|
+
# ---------------------------------------------------------------
|
|
292
297
|
|
|
293
298
|
def points
|
|
294
299
|
params = {}
|
|
@@ -296,28 +301,27 @@ class ScatterPlot
|
|
|
296
301
|
params[:size] = @size_by if @size_by
|
|
297
302
|
R.geom_point(E.aes(params))
|
|
298
303
|
end
|
|
299
|
-
|
|
300
|
-
|
|
304
|
+
|
|
305
|
+
# ---------------------------------------------------------------
|
|
301
306
|
# Plots the scatterplot
|
|
302
|
-
|
|
307
|
+
# ---------------------------------------------------------------
|
|
303
308
|
|
|
304
309
|
def plot
|
|
305
310
|
gg = @data.ggplot(E.aes(x: @x, y: @y)) +
|
|
306
|
-
points +
|
|
311
|
+
points +
|
|
307
312
|
R.geom_smooth(method: @method, se: @confidence) +
|
|
308
313
|
R.xlim(R.c(0, 0.1)) +
|
|
309
|
-
R.ylim(R.c(0, 500000)) +
|
|
314
|
+
R.ylim(R.c(0, 500000)) +
|
|
310
315
|
graph_params(title: @title,
|
|
311
|
-
subtitle: @subtitle,
|
|
312
|
-
y_label: @y_label,
|
|
313
|
-
x_label: @x_label,
|
|
316
|
+
subtitle: @subtitle,
|
|
317
|
+
y_label: @y_label,
|
|
318
|
+
x_label: @x_label,
|
|
314
319
|
caption: @caption) +
|
|
315
320
|
CorpTheme.global_theme
|
|
316
321
|
|
|
317
322
|
puts gg
|
|
318
|
-
|
|
319
323
|
end
|
|
320
|
-
|
|
324
|
+
|
|
321
325
|
end
|
|
322
326
|
```
|
|
323
327
|
|
|
@@ -334,9 +338,10 @@ sp.subtitle = "Area Vs Population"
|
|
|
334
338
|
sp.caption = "Source: midwest"
|
|
335
339
|
sp.x_label = "Area"
|
|
336
340
|
sp.y_label = "Population"
|
|
337
|
-
|
|
341
|
+
# try: sp.group_by(color: :state)
|
|
342
|
+
sp.group_by(color: :state, size: :popdensity)
|
|
338
343
|
# available methods: "lm", "glm", "loess", "gam"
|
|
339
|
-
sp.add_smoothing_line(method: "glm")
|
|
344
|
+
sp.add_smoothing_line(method: "glm")
|
|
340
345
|
sp.plot
|
|
341
346
|
```
|
|
342
347
|
|
|
@@ -347,9 +352,10 @@ sp.plot
|
|
|
347
352
|
R is a very powerful language for statistical analysis, data analytics,
|
|
348
353
|
machine learning, plotting and many other scientific applications with a
|
|
349
354
|
very large package ecosystem. However R is often considered hard to
|
|
350
|
-
learn and lacking modern
|
|
351
|
-
|
|
352
|
-
|
|
355
|
+
learn and lacking modern language features such as object-oriented
|
|
356
|
+
classes, modules, and first-class functions. For that reason, many teams
|
|
357
|
+
have standardized on Python (or stayed entirely inside R) rather than
|
|
358
|
+
mixing ecosystems.
|
|
353
359
|
|
|
354
360
|
With Galaaz, R programmers can almost transparently migrate from R to
|
|
355
361
|
Ruby, since syntax is almost identical and **GNU R** remains the engine
|
|
@@ -359,6 +365,7 @@ nicely complement R packages.
|
|
|
359
365
|
|
|
360
366
|
For the Ruby developer, Galaaz allows the immediate use of R functions
|
|
361
367
|
with minimal ceremony. As shown in the second example above, class
|
|
362
|
-
`ScatterPlot` hides most R call details from the Ruby developer.
|
|
363
|
-
|
|
364
|
-
to the JVM ecosystem; **CRuby** works equally for the Galaaz
|
|
368
|
+
`ScatterPlot` hides most R call details from the Ruby developer. Prefer
|
|
369
|
+
**JRuby** when you want **real parallel threads** on the Ruby side and
|
|
370
|
+
access to the JVM ecosystem; **CRuby** works equally for the Galaaz
|
|
371
|
+
bridge itself.
|