galaaz 2.1.7 → 2.1.9

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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/Rakefile +20 -2
  4. data/bin/check_gemfile_lock_version +46 -0
  5. data/bin/release_bump +26 -0
  6. data/blogs/README.md +4 -0
  7. data/blogs/galaaz_2_0/galaaz_2_0.Rmd +385 -0
  8. data/blogs/galaaz_2_0/galaaz_2_0.md +409 -0
  9. data/blogs/galaaz_2_0/galaaz_2_0.tex +756 -0
  10. data/blogs/galaaz_2_0/images/galaaz-header.png +0 -0
  11. data/blogs/galaaz_2_0/images/galaaz-lockup-stacked.png +0 -0
  12. data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +76 -58
  13. data/blogs/galaaz_ggplot/galaaz_ggplot.md +188 -161
  14. data/blogs/galaaz_ggplot/galaaz_ggplot.tex +185 -117
  15. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
  16. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
  17. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/midwest_rb.png +0 -0
  18. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/scatter_plot_rb.png +0 -0
  19. data/blogs/galaaz_ggplot/images/galaaz-lockup-stacked.png +0 -0
  20. data/blogs/gknit/gknit.Rmd +48 -28
  21. data/blogs/gknit/gknit.md +60 -43
  22. data/blogs/gknit/gknit.tex +1409 -0
  23. data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
  24. data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
  25. data/blogs/gknit/gknit_files/figure-latex/bubble-1.png +0 -0
  26. data/blogs/gknit/images/galaaz-lockup-stacked.png +0 -0
  27. data/blogs/manual/images/galaaz-lockup-stacked.png +0 -0
  28. data/blogs/manual/manual.Rmd +161 -71
  29. data/blogs/manual/manual.md +573 -482
  30. data/blogs/manual/manual.tex +1113 -517
  31. data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
  32. data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
  33. data/blogs/manual/manual_files/figure-markdown_github/bubble-1.png +0 -0
  34. data/blogs/manual/manual_files/figure-markdown_github/diverging_bar.png +0 -0
  35. data/blogs/nse_dplyr/images/galaaz-lockup-stacked.png +0 -0
  36. data/blogs/nse_dplyr/nse_dplyr.Rmd +42 -8
  37. data/blogs/nse_dplyr/nse_dplyr.md +69 -50
  38. data/blogs/nse_dplyr/nse_dplyr.tex +1626 -0
  39. data/blogs/oh_my/images/galaaz-lockup-stacked.png +0 -0
  40. data/blogs/oh_my/oh_my.Rmd +206 -55
  41. data/blogs/oh_my/oh_my.md +247 -96
  42. data/blogs/oh_my/oh_my.tex +2038 -93
  43. data/blogs/r_on_rails_ledger/images/00_portfolio_page.png +0 -0
  44. data/blogs/r_on_rails_ledger/images/01_results_panel.png +0 -0
  45. data/blogs/r_on_rails_ledger/images/02_density_tail_risk.png +0 -0
  46. data/blogs/r_on_rails_ledger/images/03_mc_cone.png +0 -0
  47. data/blogs/r_on_rails_ledger/images/04_rolling_var.png +0 -0
  48. data/blogs/r_on_rails_ledger/images/galaaz-lockup-stacked.png +0 -0
  49. data/blogs/r_on_rails_ledger/r_on_rails_ledger.Rmd +354 -0
  50. data/blogs/r_on_rails_ledger/r_on_rails_ledger.md +365 -0
  51. data/blogs/r_on_rails_ledger/r_on_rails_ledger.tex +670 -0
  52. data/blogs/ruby_plot/images/galaaz-lockup-stacked.png +0 -0
  53. data/blogs/ruby_plot/ruby_plot.Rmd +56 -35
  54. data/blogs/ruby_plot/ruby_plot.md +63 -47
  55. data/blogs/ruby_plot/ruby_plot.tex +194 -125
  56. data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
  57. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
  58. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
  59. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
  60. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
  61. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
  62. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
  63. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
  64. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.png +0 -0
  65. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
  66. data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
  67. data/blogs/ruby_plot/ruby_plot_files/figure-latex/dose_len.png +0 -0
  68. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
  69. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
  70. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
  71. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
  72. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
  73. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
  74. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
  75. data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
  76. data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
  77. data/blogs/ruby_plot/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
  78. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/dose_len.png +0 -0
  79. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
  80. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
  81. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
  82. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
  83. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
  84. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
  85. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
  86. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
  87. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
  88. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
  89. data/lib/galaaz/cli.rb +98 -13
  90. data/logos/icon-font/README.md +27 -0
  91. data/logos/icon-font/build_font.py +130 -0
  92. data/logos/icon-font/galaaz-mark.svg +34 -0
  93. data/script/omarchy/README.md +9 -2
  94. data/script/omarchy/fonts/galaaz.ttf +0 -0
  95. data/script/omarchy/galaaz-guide.sh +1 -1
  96. data/script/omarchy/install-galaaz.sh +8 -1
  97. data/script/omarchy/omarchy-menu.jsonc +21 -9
  98. data/sty/galaaz-header.png +0 -0
  99. data/sty/galaaz-headers-from-p3.tex +4 -0
  100. data/sty/galaaz.sty +76 -23
  101. data/version.rb +1 -1
  102. metadata +46 -7
  103. data/blogs/galaaz_ggplot/galaaz_ggplot.log +0 -754
  104. data/blogs/manual/manual.log +0 -1786
  105. data/blogs/nse_dplyr/nse_dplyr.log +0 -928
  106. data/blogs/oh_my/oh_my.log +0 -804
  107. data/blogs/ruby_plot/ruby_plot.log +0 -885
@@ -1,36 +1,65 @@
1
+ ---
2
+ title: "Ruby Plotting with Galaaz"
3
+ subtitle: "An example of tightly coupling Ruby and R (JRuby or CRuby + GNU R, Galaaz 2.0)"
4
+ author: "Rodrigo Botafogo"
5
+ tags: [Galaaz, Ruby, R, JRuby, CRuby, "GNU R", ggplot2]
6
+ date: "16 October 2018 (narrative updated for Galaaz 2.0, 2026)"
7
+ output:
8
+ html_document:
9
+ self_contained: true
10
+ keep_md: true
11
+ toc: true
12
+ toc_float: true
13
+ toc_depth: 2
14
+ number_sections: true
15
+ includes:
16
+ before_body: _logo_before_body.html
17
+ pdf_document:
18
+ includes:
19
+ in_header:
20
+ - "../../sty/galaaz.sty"
21
+ - "../../sty/galaaz-headers-from-p3.tex"
22
+ keep_tex: yes
23
+ number_sections: yes
24
+ toc: true
25
+ toc_depth: 2
26
+ md_document:
27
+ variant: markdown_github
28
+ fontsize: 11pt
29
+ ---
30
+
31
+
32
+
33
+
34
+
1
35
  # Introduction
2
36
 
3
- Galaaz is a system for tightly coupling Ruby and R. Ruby is a powerful
4
- language, with a large community, a very large set of libraries and
5
- great for web development. However, it lacks libraries for data science,
6
- statistics, scientific plotting and machine learning. On the other hand,
7
- R is considered one of the most powerful languages for solving all of
8
- the above problems. Maybe the strongest competitor to R is Python with
9
- libraries such as NumPy, Panda, SciPy, SciKit-Learn and a couple more.
10
-
11
- With Galaaz we do not intend to re-implement any of the scientific
12
- libraries in R; we allow for very tight coupling between the two
13
- languages to the point that the Ruby developer does not need to think
14
- about R syntax for every call. **Galaaz 2.0** does this with
15
- **[JRuby](https://www.jruby.org/)** or **CRuby** and **GNU R**: a **bridge**
16
- evaluates R from Ruby and exchanges data between processes.
17
-
18
- An **earlier** Galaaz prototype used Oracle’s **GraalVM** with
19
- **TruffleRuby** and **FastR** in one JVM. That stack is **historical**;
20
- today’s documentation and tooling assume **NewBridge on JRuby or CRuby**
37
+ Galaaz is a system for tightly coupling Ruby and R. Ruby is a powerful language, with
38
+ a large community, a very large set of libraries and great for web development. However,
39
+ it lacks libraries for data science, statistics, scientific plotting and machine learning.
40
+ On the other hand, R is considered one of the most powerful languages for solving all of the
41
+ above problems. **Python** is a strong competitor: NumPy, pandas, SciPy, and scikit-learn are
42
+ widely used examples among **many thousands** of packages on PyPI for numerical and ML work.
43
+
44
+ With Galaaz we do not intend to re-implement any of the scientific libraries in R; we allow
45
+ for very tight coupling between the two languages to the point that the Ruby developer does
46
+ not need to think about R syntax for every call. **Galaaz 2.0** does this with **[JRuby](https://www.jruby.org/)**
47
+ or **CRuby** and **GNU R**: a **bridge** evaluates R from Ruby and exchanges data between processes.
48
+
49
+ An **earlier** Galaaz prototype used Oracle’s **GraalVM** with **TruffleRuby** and **FastR** in one JVM.
50
+ That stack is **historical**; today’s documentation and tooling assume **NewBridge on JRuby or CRuby**
21
51
  (see the project manual and **`bin/galaaz-ruby`** / **`bin/gknit`**).
22
52
 
23
53
  For background on the old stack:
24
54
 
25
- - [GraalVM Home](https://www.graalvm.org/)
26
- - [TruffleRuby](https://github.com/oracle/truffleruby)
27
- - [FastR](https://github.com/oracle/fastr)
28
- - [Faster R with
29
- FastR](https://medium.com/graalvm/faster-r-with-fastr-4b8db0e0dceb)
55
+ * [GraalVM Home](https://www.graalvm.org/)
56
+ * [TruffleRuby](https://github.com/oracle/truffleruby)
57
+ * [FastR](https://github.com/oracle/fastr)
58
+ * [Faster R with FastR](https://medium.com/graalvm/faster-r-with-fastr-4b8db0e0dceb)
30
59
 
31
60
  ## What does Galaaz mean
32
61
 
33
- Galaaz is the Portuguese name for “Galahad”. From Wikipedia:
62
+ Galaaz is the Portuguese name for "Galahad". From Wikipedia:
34
63
 
35
64
  Sir Galahad (sometimes referred to as Galeas or Galath),
36
65
  in Arthurian legend, is a knight of King Arthur's Round Table and one
@@ -47,57 +76,53 @@ Galaaz is the Portuguese name for “Galahad”. From Wikipedia:
47
76
 
48
77
  ## Prerequisites (Galaaz 2.0)
49
78
 
50
- - **JRuby** and a compatible **JDK**, *or* **CRuby 3.3+**
51
- - **GNU R** on your `PATH`
79
+ * **JRuby** and a compatible **JDK**, *or* **CRuby 3.3+**
80
+ * **GNU R** on your `PATH`
52
81
 
53
- The following R packages will be automatically installed when necessary,
54
- but could be installed prior to the demo if desired:
82
+ The following R packages will be automatically installed when necessary, but could be installed prior
83
+ to the demo if desired:
55
84
 
56
- - ggplot2
57
- - gridExtra
85
+ * ggplot2
86
+ * gridExtra
58
87
 
59
- Installation of R packages requires a development environment. In Linux,
60
- the gnu compiler and tools should be enough. I am not sure what is
61
- needed on the Mac.
88
+ Installation of R packages requires a development environment. On Linux, a typical build toolchain
89
+ (GCC, headers) is usually enough. On macOS, Apple’s **Xcode Command Line Tools** are commonly required.
62
90
 
63
- In order to run the ‘specs’ the following Ruby package is necessary:
91
+ In order to run the 'specs' the following Ruby package is necessary:
64
92
 
65
- - gem install rspec
93
+ * gem install rspec
66
94
 
67
95
  ## Preparation
68
96
 
69
- - gem install galaaz
97
+ * gem install galaaz
70
98
 
71
99
  ## Running the demo
72
100
 
73
- The ggplot for this demos was extracted from:
74
- <http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html>.
101
+ The ggplot examples for this demo were adapted from: http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html.
75
102
 
76
- On the console do
103
+ At the shell, from a suitable Galaaz environment:
77
104
 
78
- > galaaz master_list:scatter_plot
105
+ galaaz master_list:scatter_plot
79
106
 
80
107
  ## Running other demos
81
108
 
82
- Doing on the console
109
+ Running
83
110
 
84
- > galaaz -T
111
+ galaaz -T
85
112
 
86
- will show a list with all available demos. To run any of the demos in
87
- the list, substitute the call to ‘rake’ to ‘galaaz’. For instance, one
88
- of the examples in the list is ‘rake sthda:bar’. In order to run this
89
- example just do ‘galaaz sthda:bar’. Doing ‘galaaz sthda:all’ will run
90
- all demos in the sthda cathegory. Some of the examples require ‘rspec’
91
- do be available. To install ‘rspec’ just do ‘gem install rspec’.
113
+ lists available demo tasks. To run a demo, use **`galaaz`** where you would otherwise invoke **`rake`**.
114
+ For example, if the list shows `rake sthda:bar`, run `galaaz sthda:bar`. To run every demo in the **sthda**
115
+ category, use `galaaz sthda:all`. Some examples require **rspec**; install it with `gem install rspec`.
92
116
 
93
117
  # The demo code
94
118
 
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 bellow.
97
- If the example is ran, the plot will appear on the screen, bellow, we
98
- generate an ‘svg’ image and then include it in this document. In order
99
- to generate and image, the R.svg device is used. To generate the plot on
100
- the screen, use the R.awt device, as commented on the code.
119
+
120
+ The following is the Ruby code and plot for the above example. There is a small difference between
121
+ the code in the example and the code below. If the example is **run**, the plot will appear on the
122
+ screen; below, we generate an SVG image and then include it in this document. In order to
123
+ generate and image, the R.svg device is used. To generate the plot on the screen, use the R.awt
124
+ device, as commented on the code.
125
+
101
126
 
102
127
  ``` ruby
103
128
  require 'galaaz'
@@ -124,10 +149,13 @@ gg = midwest.ggplot(E.aes(x: :area, y: :poptotal)) +
124
149
  puts gg
125
150
  ```
126
151
 
127
- ![](galaaz_ggplot_files/figure-markdown_github/midwest_rb.png)
152
+
153
+ ![](galaaz_ggplot_files/figure-html/midwest_rb.png)
154
+
128
155
 
129
156
  In R, the code to generate this plot is the following
130
157
 
158
+
131
159
  ``` r
132
160
  # install.packages("ggplot2")
133
161
  # load package and data
@@ -152,87 +180,88 @@ gg <- ggplot(midwest, aes(x=area, y=poptotal)) +
152
180
  plot(gg)
153
181
  ```
154
182
 
155
- Note that both codes are very similar. The Ruby code requires the use of
156
- “R.” before calling any functions, for instance R function ‘geom_point’
157
- becomes ‘R.geom_point’ in Ruby. R named parameters such as (col = state,
158
- size = popdensity), become in Ruby (col: :state, size: :popdensity).
159
-
160
- One last point that needs to be observed is the call to the ‘aes’
161
- function. In Ruby instead of doing ‘R.aes’, we use ‘E.aes’. The
162
- explanation of why E.aes is needed is an advanced topic in R and depends
163
- on what is know as Non-standard Evaluation (NSE) in R. In short,
164
- function ‘aes’ is lazily evaluated in R, i.e., in R when calling
165
- geom_point(aes(col=state, size=popdensity)), function geom_point
166
- receives as argument something similar to a string containing
167
- ‘aes(col=state, size=popdensity)’, and the aes function will be
168
- evaluated inside the geom_point function. In Ruby, there is no Lazy
169
- evaluation and doing R.aes would try to evaluate aes immediately. In
170
- order to delay the evaluation of function aes we need to use E.aes. The
171
- interested reader on NSE in R is directed to
172
- <http://adv-r.had.co.nz/Computing-on-the-language.html>.
183
+ Note that both codes are very similar. The Ruby code requires the use of "R." before calling
184
+ any functions,
185
+ for instance R function 'geom_point' becomes 'R.geom_point' in Ruby. R named parameters such as
186
+ (col = state, size = popdensity), become in Ruby (col: :state, size: :popdensity).
187
+
188
+ One last
189
+ point that needs to be observed is the call to the 'aes' function. In Ruby instead of doing
190
+ 'R.aes', we use 'E.aes'. The explanation of why E.aes is needed is an advanced topic in R and
191
+ depends on what is know as Non-standard Evaluation (NSE) in R. In short, function 'aes' is lazily
192
+ evaluated in R, i.e., in R when calling geom_point(aes(col=state, size=popdensity)), function
193
+ geom_point receives as argument something similar to a string containing
194
+ 'aes(col=state, size=popdensity)', and the aes function will be evaluated inside the geom_point
195
+ function. In Ruby, there is no Lazy evaluation and doing R.aes would try to evaluate aes
196
+ immediately. In order to delay the evaluation of function aes we need to use E.aes. The
197
+ interested reader on NSE in R is directed to http://adv-r.had.co.nz/Computing-on-the-language.html.
173
198
 
174
199
  # An extension to the example
175
200
 
176
- If both codes are so similar, then why would one use Ruby instead of R
177
- and what good is galaaz after all?
201
+ If both codes are so similar, then why would one use Ruby instead of R and what good is galaaz
202
+ after all?
178
203
 
179
- Ruby is a modern OO language with numerous very useful constructs such
180
- as classes, modules, blocks, procs, etc. The example above focus on the
181
- coupling of both languages, and does not show the use of other Ruby
182
- constructs. In the following example, we will show a more complex
183
- example using other Ruby constructs. This is certainly not a very well
184
- written and robust Ruby code, but it give the idea of how Ruby and R are
185
- strongly coupled.
204
+ Ruby is a modern OO language with numerous very useful constructs such as classes, modules, blocks,
205
+ procs, etc. The example above focus on the coupling of both languages, and does not show the
206
+ use of other Ruby constructs. In the following example, we will show a more complex example using
207
+ other Ruby constructs. This is certainly not a very well written and robust Ruby code, but
208
+ it give the idea of how Ruby and R are strongly coupled.
209
+
210
+ Let's imagine that we work in a corporation that has its plot themes. So, it has defined a
211
+ 'CorpTheme' module. Plots in this corporation should not have grids, numbers in labels should
212
+ not use scientific notation and the preferred color is blue.
186
213
 
187
- Let’s imagine that we work in a corporation that has its plot themes.
188
- So, it has defined a ‘CorpTheme’ module. Plots in this corporation
189
- should not have grids, numbers in labels should not use scientific
190
- notation and the preferred color is blue.
191
214
 
192
215
  ``` ruby
193
216
  # corp_theme.rb
194
217
  # defines the corporate theme for all plots
195
-
218
+
196
219
  module CorpTheme
197
220
 
198
- #---------------------------------------------------------------------------------
199
- # Defines the plot theme (visualization). In this theme we remove major and minor
200
- # grids, borders and background. We also turn-off scientific notation.
201
- #---------------------------------------------------------------------------------
202
-
221
+ # ---------------------------------------------------------------
222
+ # Plot theme: no major/minor grids, borders, or background;
223
+ # turn off scientific notation.
224
+ # ---------------------------------------------------------------
225
+
203
226
  def self.global_theme
204
-
227
+
205
228
  R.options(scipen: 999) # turn-off scientific notation like 1e+48
206
-
229
+
207
230
  # remove major grids
208
- global_theme = R.theme(panel__grid__major: E.element_blank())
231
+ global_theme =
232
+ R.theme(panel__grid__major: E.element_blank())
209
233
  # remove minor grids
210
- global_theme = global_theme + R.theme(panel__grid__minor: E.element_blank)
234
+ global_theme = global_theme +
235
+ R.theme(panel__grid__minor: E.element_blank)
211
236
  # remove border
212
- global_theme = global_theme + R.theme(panel__border: E.element_blank)
237
+ global_theme = global_theme +
238
+ R.theme(panel__border: E.element_blank)
213
239
  # remove background
214
- global_theme = global_theme + R.theme(panel__background: E.element_blank)
240
+ global_theme = global_theme +
241
+ R.theme(panel__background: E.element_blank)
215
242
  # Change axis font
216
243
  global_theme = global_theme +
217
- R.theme(axis__text: E.element_text(size: 8, color: "#000080"))
244
+ R.theme(axis__text: E.element_text(
245
+ size: 8, color: "#000080"))
218
246
  # change color of axis titles
219
247
  global_theme = global_theme +
220
- R.theme(axis__title: E.element_text(
221
- color: "#000080",
222
- face: "bold",
223
- size: 8,
224
- hjust: 1))
248
+ R.theme(axis__title: E.element_text(
249
+ color: "#000080",
250
+ face: "bold",
251
+ size: 8,
252
+ hjust: 1))
225
253
  end
226
-
254
+
227
255
  end
228
256
  ```
229
257
 
230
258
  We now define a ScatterPlot class:
231
259
 
260
+
232
261
  ``` ruby
233
262
  # ScatterPlot.rb
234
263
  # creates a scatter plot and allow some configuration
235
-
264
+
236
265
  class ScatterPlot
237
266
 
238
267
  attr_accessor :title
@@ -240,55 +269,55 @@ class ScatterPlot
240
269
  attr_accessor :caption
241
270
  attr_accessor :x_label
242
271
  attr_accessor :y_label
243
-
244
- #---------------------------------------------------------------------------------
272
+
273
+ # ---------------------------------------------------------------
245
274
  # Initialize the plot with the data and the x and y variables
246
- #---------------------------------------------------------------------------------
275
+ # ---------------------------------------------------------------
247
276
 
248
277
  def initialize(data, x:, y:)
249
278
  @data = data
250
279
  @x = x
251
280
  @y = y
252
281
  end
253
-
254
- #---------------------------------------------------------------------------------
282
+
283
+ # ---------------------------------------------------------------
255
284
  # Define groupings by color and size
256
- #---------------------------------------------------------------------------------
285
+ # ---------------------------------------------------------------
257
286
 
258
287
  def group_by(color:, size:)
259
288
  @color_by = color
260
289
  @size_by = size
261
290
  end
262
291
 
263
- #---------------------------------------------------------------------------------
264
- # Add a smoothing line, and if confidence is true the add a confidence interval, if
265
- # false does not add the confidence interval
266
- #---------------------------------------------------------------------------------
292
+ # ---------------------------------------------------------------
293
+ # Add a smoothing line; confidence: true draws a CI band.
294
+ # ---------------------------------------------------------------
267
295
 
268
296
  def add_smoothing_line(method:, confidence: true)
269
297
  @method = method
270
298
  @confidence = confidence
271
299
  end
272
-
273
- #---------------------------------------------------------------------------------
274
- # Creates the graph title, properly formated for this theme
275
- # @param title [String] The title to add to the graph
276
- # @return textGrob that can be included in a graph
277
- #---------------------------------------------------------------------------------
278
-
279
- def graph_params(title: "", subtitle: "", caption: "", x_label: "", y_label: "")
300
+
301
+ # ---------------------------------------------------------------
302
+ # Graph title / labels, formatted for this theme.
303
+ # @param title [String] title to add to the graph
304
+ # @return labs() result that can be included in a graph
305
+ # ---------------------------------------------------------------
306
+
307
+ def graph_params(title: "", subtitle: "", caption: "",
308
+ x_label: "", y_label: "")
280
309
  R.labs(
281
- title: title,
282
- subtitle: subtitle,
310
+ title: title,
311
+ subtitle: subtitle,
283
312
  caption: caption,
284
- y_label: y_label,
285
- x_label: x_label,
313
+ y_label: y_label,
314
+ x_label: x_label,
286
315
  )
287
316
  end
288
317
 
289
- #---------------------------------------------------------------------------------
318
+ # ---------------------------------------------------------------
290
319
  # Prepare the plot's points
291
- #---------------------------------------------------------------------------------
320
+ # ---------------------------------------------------------------
292
321
 
293
322
  def points
294
323
  params = {}
@@ -296,33 +325,32 @@ class ScatterPlot
296
325
  params[:size] = @size_by if @size_by
297
326
  R.geom_point(E.aes(params))
298
327
  end
299
-
300
- #---------------------------------------------------------------------------------
328
+
329
+ # ---------------------------------------------------------------
301
330
  # Plots the scatterplot
302
- #---------------------------------------------------------------------------------
331
+ # ---------------------------------------------------------------
303
332
 
304
333
  def plot
305
334
  gg = @data.ggplot(E.aes(x: @x, y: @y)) +
306
- points +
335
+ points +
307
336
  R.geom_smooth(method: @method, se: @confidence) +
308
337
  R.xlim(R.c(0, 0.1)) +
309
- R.ylim(R.c(0, 500000)) +
338
+ R.ylim(R.c(0, 500000)) +
310
339
  graph_params(title: @title,
311
- subtitle: @subtitle,
312
- y_label: @y_label,
313
- x_label: @x_label,
340
+ subtitle: @subtitle,
341
+ y_label: @y_label,
342
+ x_label: @x_label,
314
343
  caption: @caption) +
315
344
  CorpTheme.global_theme
316
345
 
317
346
  puts gg
318
-
319
347
  end
320
-
348
+
321
349
  end
322
350
  ```
323
351
 
324
- And this is the final code for making the scatter plot with the midwest
325
- data
352
+ And this is the final code for making the scatter plot with the midwest data
353
+
326
354
 
327
355
  ``` ruby
328
356
  require 'galaaz'
@@ -334,31 +362,30 @@ sp.subtitle = "Area Vs Population"
334
362
  sp.caption = "Source: midwest"
335
363
  sp.x_label = "Area"
336
364
  sp.y_label = "Population"
337
- sp.group_by(color: :state, size: :popdensity) # try sp.group_by(color: :state)
365
+ # try: sp.group_by(color: :state)
366
+ sp.group_by(color: :state, size: :popdensity)
338
367
  # available methods: "lm", "glm", "loess", "gam"
339
- sp.add_smoothing_line(method: "glm")
368
+ sp.add_smoothing_line(method: "glm")
340
369
  sp.plot
341
370
  ```
342
371
 
343
- ![](galaaz_ggplot_files/figure-markdown_github/scatter_plot_rb.png)
372
+
373
+ ![](galaaz_ggplot_files/figure-html/scatter_plot_rb.png)
344
374
 
345
375
  # Conclusion
346
376
 
347
- R is a very powerful language for statistical analysis, data analytics,
348
- machine learning, plotting and many other scientific applications with a
349
- very large package ecosystem. However R is often considered hard to
350
- learn and lacking modern computer languages constructs such as object
351
- oriented classes, modules, lambdas, etc. For this reason, many
352
- developers have started or switched from R to Python.
353
-
354
- With Galaaz, R programmers can almost transparently migrate from R to
355
- Ruby, since syntax is almost identical and **GNU R** remains the engine
356
- for statistics and **ggplot2**. Further, by using Galaaz the R developer
357
- can start (slowly if needed) using Ruby’s constructs and libraries that
377
+ R is a very powerful language for statistical analysis, data analytics, machine learning, plotting
378
+ and many other scientific applications with a very large package ecosystem. However R is often
379
+ considered hard to learn and lacking modern language features such as object-oriented
380
+ classes, modules, and first-class functions. For that reason, many teams have standardized on
381
+ Python (or stayed entirely inside R) rather than mixing ecosystems.
382
+
383
+ With Galaaz, R programmers can almost transparently migrate from R to Ruby, since syntax is
384
+ almost identical and **GNU R** remains the engine for statistics and **ggplot2**. Further, by using
385
+ Galaaz the R developer can start (slowly if needed) using Ruby’s constructs and libraries that
358
386
  nicely complement R packages.
359
387
 
360
- For the Ruby developer, Galaaz allows the immediate use of R functions
361
- with minimal ceremony. As shown in the second example above, class
362
- `ScatterPlot` hides most R call details from the Ruby developer.
363
- Prefer **JRuby** when you want **real parallel threads** on the Ruby side and access
364
- to the JVM ecosystem; **CRuby** works equally for the Galaaz bridge itself.
388
+ For the Ruby developer, Galaaz allows the immediate use of R functions with minimal ceremony. As
389
+ shown in the second example above, class `ScatterPlot` hides most R call details from the Ruby
390
+ developer. Prefer **JRuby** when you want **real parallel threads** on the Ruby side and access to
391
+ the JVM ecosystem; **CRuby** works equally for the Galaaz bridge itself.