galaaz 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +696 -270
  3. data/Rakefile +9 -22
  4. data/bin/gknit +2 -217
  5. data/bin/gknit_old_r +236 -0
  6. data/bin/grun +5 -0
  7. data/blogs/dev/dev.Rmd +7 -0
  8. data/blogs/dev/dev.html +34 -26
  9. data/blogs/dev/dev.md +40 -25
  10. data/blogs/dev/dev_files/figure-html/bubble-1.png +0 -0
  11. data/blogs/dev/dev_files/figure-html/diverging_bar. +0 -0
  12. data/blogs/dev/dev_files/figure-html/diverging_bar.png +0 -0
  13. data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +4 -4
  14. data/blogs/galaaz_ggplot/galaaz_ggplot.html +251 -59
  15. data/blogs/galaaz_ggplot/galaaz_ggplot.log +640 -0
  16. data/blogs/galaaz_ggplot/galaaz_ggplot.md +199 -95
  17. data/blogs/galaaz_ggplot/galaaz_ggplot.tex +45 -228
  18. data/blogs/galaaz_ggplot/midwest.png +0 -0
  19. data/blogs/galaaz_ggplot/scatter_plot.png +0 -0
  20. data/blogs/gknit/gknit.Rmd +271 -148
  21. data/blogs/manual/manual.Rmd +212 -0
  22. data/blogs/manual/manual.html +1832 -0
  23. data/blogs/manual/manual.md +751 -0
  24. data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
  25. data/blogs/ruby_plot/ruby_plot.Rmd +5 -69
  26. data/blogs/ruby_plot/ruby_plot.html +195 -236
  27. data/blogs/ruby_plot/ruby_plot.md +1 -261
  28. data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.svg +38 -38
  29. data/examples/sthda_ggplot/two_variables_disc_cont/geom_dotplot.rb +5 -5
  30. data/examples/sthda_ggplot/two_variables_disc_cont/geom_jitter.rb +1 -0
  31. data/examples/sthda_ggplot/two_variables_disc_cont/geom_violin.rb +3 -7
  32. data/examples/sthda_ggplot/two_variables_error/geom_crossbar.rb +3 -1
  33. data/lib/R_interface/r.rb +12 -9
  34. data/lib/R_interface/r_methods.rb +2 -2
  35. data/lib/R_interface/rbinary_operators.rb +2 -20
  36. data/lib/R_interface/rdata_frame.rb +56 -9
  37. data/lib/R_interface/rdevices.R +0 -12
  38. data/lib/R_interface/rexpression.rb +0 -97
  39. data/lib/R_interface/rindexed_object.rb +12 -3
  40. data/lib/R_interface/rlanguage.rb +1 -1
  41. data/lib/R_interface/rlist.rb +29 -4
  42. data/lib/R_interface/rlogical_operators.rb +50 -0
  43. data/lib/R_interface/rmatrix.rb +7 -1
  44. data/lib/R_interface/robject.rb +29 -15
  45. data/lib/R_interface/rsupport.rb +74 -58
  46. data/lib/R_interface/rsymbol.rb +2 -1
  47. data/lib/R_interface/ruby_extensions.rb +11 -2
  48. data/lib/R_interface/rvector.rb +26 -11
  49. data/lib/gknit.rb +2 -0
  50. data/lib/gknit/include_engine.rb +57 -0
  51. data/lib/gknit/knitr_engine.rb +596 -50
  52. data/lib/gknit/rb_engine.rb +56 -0
  53. data/lib/gknit/ruby_engine.rb +13 -36
  54. data/lib/util/exec_ruby.rb +132 -21
  55. data/lib/util/inline_file.rb +9 -7
  56. data/specs/all.rb +5 -0
  57. data/specs/figures/bg.jpeg +0 -0
  58. data/specs/figures/bg.png +0 -0
  59. data/specs/figures/bg.svg +57 -0
  60. data/specs/figures/no_args.jpeg +0 -0
  61. data/specs/figures/no_args.png +0 -0
  62. data/specs/figures/no_args.svg +57 -0
  63. data/specs/figures/width_height.jpeg +0 -0
  64. data/specs/figures/width_height.png +0 -0
  65. data/specs/figures/width_height_units1.jpeg +0 -0
  66. data/specs/figures/width_height_units1.png +0 -0
  67. data/specs/figures/width_height_units2.jpeg +0 -0
  68. data/specs/figures/width_height_units2.png +0 -0
  69. data/specs/r_dataframe.spec.rb +29 -27
  70. data/specs/r_devices.spec.rb +347 -0
  71. data/specs/r_eval.spec.rb +10 -3
  72. data/specs/r_formula.spec.rb +2 -2
  73. data/specs/r_language.spec.rb +112 -0
  74. data/specs/r_list.spec.rb +174 -14
  75. data/specs/r_list_apply.spec.rb +17 -10
  76. data/specs/r_matrix.spec.rb +3 -3
  77. data/specs/r_vector_operators.spec.rb +13 -7
  78. data/specs/tmp.rb +42 -12
  79. data/version.rb +1 -1
  80. metadata +28 -24
  81. data/bin/gknit2 +0 -14
  82. data/bin/prepareR.rb +0 -3
  83. data/bin/tmp.py +0 -51
  84. data/blogs/gknit/gknit.html +0 -528
  85. data/blogs/gknit/gknit.md +0 -628
  86. data/blogs/gknit/gknit.pdf +0 -0
  87. data/blogs/gknit/gknit.tex +0 -745
  88. data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
  89. data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
  90. data/blogs/ruby_plot/figures/dose_len.png +0 -0
  91. data/blogs/ruby_plot/figures/facet_by_delivery.png +0 -0
  92. data/blogs/ruby_plot/figures/facet_by_dose.png +0 -0
  93. data/blogs/ruby_plot/figures/facets_by_delivery_color.png +0 -0
  94. data/blogs/ruby_plot/figures/facets_by_delivery_color2.png +0 -0
  95. data/blogs/ruby_plot/figures/facets_with_decorations.png +0 -0
  96. data/blogs/ruby_plot/figures/facets_with_jitter.png +0 -0
  97. data/blogs/ruby_plot/figures/facets_with_points.png +0 -0
  98. data/blogs/ruby_plot/figures/final_box_plot.png +0 -0
  99. data/blogs/ruby_plot/figures/final_violin_plot.png +0 -0
  100. data/blogs/ruby_plot/figures/violin_with_jitter.png +0 -0
  101. data/lib/R/eng_ruby.R +0 -62
  102. data/lib/R_interface/rdevices.rb +0 -225
@@ -1,99 +1,148 @@
1
- ## [1] TRUE
2
-
3
- Introduction
4
- ============
5
-
6
- Galaaz is a system for tightly coupling Ruby and R. Ruby is a powerful language, with a large community, a very large set of libraries and great for web development. However, it lacks libraries for data science, statistics, scientific plotting and machine learning. On the other hand, R is considered one of the most powerful languages for solving all of the above problems. Maybe the strongest competitor to R is Python with libraries such as NumPy, Panda, SciPy, SciKit-Learn and a couple more.
7
-
8
- With Galaaz we do not intend to re-implement any of the scientific libraries in R, we allow for very tight coupling between the two languages to the point that the Ruby developer does not need to know that there is an R engine running. For this to happen we use new technologies provided by Oracle, with GraalVM, TruffleRuby and FastR:
9
-
10
- GraalVM is a universal virtual machine for running applications written in JavaScript,
11
- Python 3, Ruby, R, JVM-based languages like Java, Scala, Kotlin, and LLVM-based languages
12
- such as C and C++.
13
-
14
- GraalVM removes the isolation between programming languages and enables interoperability in a
15
- shared runtime. It can run either standalone or in the context of OpenJDK, Node.js,
16
- Oracle Database, or MySQL.
17
-
18
- GraalVM allows you to write polyglot applications with a seamless way to pass values from one
19
- language to another. With GraalVM there is no copying or marshalling necessary as it is with
20
- other polyglot systems. This lets you achieve high performance when language boundaries are
21
- crossed. Most of the time there is no additional cost for crossing a language boundary at all.
22
-
23
- Often developers have to make uncomfortable compromises that require them to rewrite
24
- their software in other languages. For example:
1
+ ---
2
+ title: "Ruby Plotting with Galaaz"
3
+ subtitle: "An example of tightly coupling Ruby and R in GraalVM"
4
+ author: "Rodrigo Botafogo"
5
+ tags: [Galaaz, Ruby, R, TruffleRuby, FastR, GraalVM, ggplot2]
6
+ date: "16 October 2018"
7
+ output:
8
+ html_document:
9
+ self_contained: true
10
+ keep_md: true
11
+ pdf_document:
12
+ includes:
13
+ in_header: "../../sty/galaaz.sty"
14
+ keep_tex: yes
15
+ number_sections: yes
16
+ toc: true
17
+ toc_depth: 2
18
+ md_document:
19
+ variant: markdown_github
20
+ fontsize: 11pt
21
+ ---
22
+
23
+
24
+
25
+ # Introduction
26
+
27
+ Galaaz is a system for tightly coupling Ruby and R. Ruby is a powerful language, with
28
+ a large community, a very large set of libraries and great for web development. However,
29
+ it lacks libraries for data science, statistics, scientific plotting and machine learning.
30
+ On the other hand, R is considered one of the most powerful languages for solving all of the
31
+ above problems. Maybe the strongest competitor to R is Python with libraries such as NumPy,
32
+ Panda, SciPy, SciKit-Learn and a couple more.
33
+
34
+ With Galaaz we do not intend to re-implement any of the scientific libraries in R, we allow
35
+ for very tight coupling between the two languages to the point that the Ruby developer does
36
+ not need to know that there is an R engine running. For this to happen we use new
37
+ technologies provided by Oracle: GraalVM, TruffleRuby and FastR:
38
+
39
+ GraalVM is a universal virtual machine for running applications
40
+ written in JavaScript, Python 3, Ruby, R, JVM-based languages like Java,
41
+ Scala, Kotlin, and LLVM-based languages such as C and C++.
42
+
43
+ GraalVM removes the isolation between programming languages and enables
44
+ interoperability in a shared runtime. It can run either standalone or in
45
+ the context of OpenJDK, Node.js, Oracle Database, or MySQL.
46
+
47
+ GraalVM allows you to write polyglot applications with a seamless way to
48
+ pass values from one language to another. With GraalVM there is no copying
49
+ or marshaling necessary as it is with other polyglot systems. This lets
50
+ you achieve high performance when language boundaries are crossed. Most
51
+ of the time there is no additional cost for crossing a language boundary
52
+ at all.
53
+
54
+ Often developers have to make uncomfortable compromises that require them
55
+ to rewrite their software in other languages. For example:
25
56
 
26
57
  * “That library is not available in my language. I need to rewrite it.”
27
- * “That language would be the perfect fit for my problem, but we cannot run it in our environment.”
28
- * “That problem is already solved in my language, but the language is too slow.”
58
+ * “That language would be the perfect fit for my problem, but we cannot
59
+ run it in our environment.”
60
+ * “That problem is already solved in my language, but the language is
61
+ too slow.”
62
+
63
+ With GraalVM we aim to allow developers to freely choose the right language
64
+ for the task at hand without making compromises.
65
+
66
+ Interested readers should also check out the following sites:
29
67
 
30
- With GraalVM we aim to allow developers to freely choose the right language for the task at
31
- hand without making compromises.
68
+ * [GraalVM Home](https://www.graalvm.org/)
69
+ * [TruffleRuby](https://github.com/oracle/truffleruby)
70
+ * [FastR](https://github.com/oracle/fastr)
71
+ * [Faster R with FastR](https://medium.com/graalvm/faster-r-with-fastr-4b8db0e0dceb)
32
72
 
33
- What does Galaaz mean
34
- ---------------------
73
+ ## What does Galaaz mean
35
74
 
36
- Galaaz is the Portuguese name for "Galahad". From Wikipedia:
75
+ Galaaz is the Portuguese name for "Galahad". From Wikipedia:
37
76
 
38
- Sir Galahad (/ˈɡæləhæd/; sometimes referred to as Galeas /ɡəˈliːəs/ or Galath /ˈɡæləθ/),
39
- in Arthurian legend, is a knight of King Arthur's Round Table and one of the three
40
- achievers of the Holy Grail. He is the illegitimate son of Sir Lancelot and Elaine of
41
- Corbenic, and is renowned for his gallantry and purity as the most perfect of all knights.
42
- Emerging quite late in the medieval Arthurian tradition, Sir Galahad first appears in the
43
- Lancelot–Grail cycle, and his story is taken up in later works such as the Post-Vulgate
44
- Cycle and Sir Thomas Malory's Le Morte d'Arthur. His name should not be mistaken with
45
- Galehaut, a different knight from Arthurian legend.
77
+ Sir Galahad (sometimes referred to as Galeas or Galath),
78
+ in Arthurian legend, is a knight of King Arthur's Round Table and one
79
+ of the three achievers of the Holy Grail. He is the illegitimate son
80
+ of Sir Lancelot and Elaine of Corbenic, and is renowned for his
81
+ gallantry and purity as the most perfect of all knights. Emerging quite
82
+ late in the medieval Arthurian tradition, Sir Galahad first appears in the
83
+ Lancelot–Grail cycle, and his story is taken up in later works such as
84
+ the Post-Vulgate Cycle and Sir Thomas Malory's Le Morte d'Arthur.
85
+ His name should not be mistaken with Galehaut, a different knight from
86
+ Arthurian legend.
46
87
 
47
- Galaaz Demo
48
- ===========
88
+ # Galaaz Demo
49
89
 
50
- Prerequisites
51
- -------------
90
+ ## Prerequisites
52
91
 
53
- - GraalVM (>= rc7)
54
- - TruffleRuby
55
- - FastR
92
+ * GraalVM (>= rc7)
93
+ * TruffleRuby
94
+ * FastR
56
95
 
57
- The following R packages will be automatically installed when necessary, but could be installed prior to the demo if desired:
96
+ The following R packages will be automatically installed when necessary, but could be installed prior
97
+ to the demo if desired:
58
98
 
59
- - ggplot2
60
- - gridExtra
99
+ * ggplot2
100
+ * gridExtra
61
101
 
62
- Installation of R packages requires a development environment. In Linux, the gnu compiler and tools should be enough. I am not sure what is needed on the Mac.
102
+ Installation of R packages requires a development environment. In Linux, the gnu compiler and
103
+ tools should be enough. I am not sure what is needed on the Mac.
63
104
 
64
105
  In order to run the 'specs' the following Ruby package is necessary:
65
106
 
66
- - gem install rspec
107
+ * gem install rspec
67
108
 
68
- Preparation
69
- -----------
109
+ ## Preparation
70
110
 
71
- - gem install galaaz
111
+ * gem install galaaz
72
112
 
73
- Running the demo
74
- ----------------
113
+ ## Running the demo
75
114
 
76
- The ggplot for this demos was extracted from: <http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html>.
115
+ The ggplot for this demos was extracted from: http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html.
77
116
 
78
117
  On the console do
79
118
 
80
119
  > galaaz master_list:scatter_plot
81
120
 
82
- Running other demos
83
- -------------------
121
+ ## Running other demos
84
122
 
85
123
  Doing on the console
86
124
 
87
125
  > galaaz -T
88
126
 
89
- will show a list with all available demos. To run any of the demos in the list, substitute the call to 'rake' to 'galaaz'. For instance, one of the examples in the list is 'rake sthda:bar'. In order to run this example just do 'galaaz sthda:bar'. Doing 'galaaz sthda:all' will run all demos in the sthda cathegory. Some of the examples require 'rspec' do be available. To install 'rspec' just do 'gem install rspec'.
127
+ will show a list with all available demos. To run any of the demos in the list,
128
+ substitute the call to
129
+ 'rake' to 'galaaz'. For instance, one of the examples in the list is 'rake sthda:bar'.
130
+ In order to run
131
+ this example just do 'galaaz sthda:bar'. Doing 'galaaz sthda:all' will run all demos in the sthda
132
+ cathegory. Some of the examples require 'rspec' do be available. To install 'rspec' just do
133
+ 'gem install rspec'.
90
134
 
91
- The demo code
92
- =============
135
+ # The demo code
93
136
 
94
- The following is the Ruby code and plot for the above example. There is a small difference between the code in the example and the code bellow. If the example is ran, the plot will appear on the screen, bellow, we generate an 'svg' image and then include it in this document. In order to generate and image, the R.svg device is used. To generate the plot on the screen, use the R.awt device, as commented on the code.
95
137
 
96
- ``` galaaz
138
+ The following is the Ruby code and plot for the above example. There is a small difference between
139
+ the code in the example and the code bellow. If the example is ran, the plot will appear on the
140
+ screen, bellow, we generate an 'svg' image and then include it in this document. In order to
141
+ generate and image, the R.svg device is used. To generate the plot on the screen, use the R.awt
142
+ device, as commented on the code.
143
+
144
+
145
+ ```ruby
97
146
  require 'galaaz'
98
147
  require 'ggplot'
99
148
 
@@ -126,11 +175,17 @@ R.dev__off # R.dev__off turns off the device. If using awt, the p
126
175
  # window will be closed
127
176
  ```
128
177
 
129
- <img src="https://user-images.githubusercontent.com/3999729/46742999-87bc2480-cc7e-11e8-9f16-31c3437e4a58.PNG" alt="Midwest Plot" style="width:70.0%" />
178
+ ```
179
+ ## This is the fake output
180
+ ```
181
+
182
+
183
+ ![Midwest Plot](midwest.png){width=70%}
130
184
 
131
185
  In R, the code to generate this plot is the following
132
186
 
133
- ``` r
187
+
188
+ ```r
134
189
  # install.packages("ggplot2")
135
190
  # load package and data
136
191
  options(scipen=999) # turn-off scientific notation like 1e+48
@@ -154,29 +209,48 @@ gg <- ggplot(midwest, aes(x=area, y=poptotal)) +
154
209
  plot(gg)
155
210
  ```
156
211
 
157
- Note that both codes are very similar. The Ruby code requires the use of "R." before calling any functions, for instance R function 'geom\_point' becomes 'R.geom\_point' in Ruby. R named parameters such as (col = state, size = popdensity), become in Ruby (col: :state, size: :popdensity).
212
+ Note that both codes are very similar. The Ruby code requires the use of "R." before calling
213
+ any functions,
214
+ for instance R function 'geom_point' becomes 'R.geom_point' in Ruby. R named parameters such as
215
+ (col = state, size = popdensity), become in Ruby (col: :state, size: :popdensity).
216
+
217
+ One last
218
+ point that needs to be observed is the call to the 'aes' function. In Ruby instead of doing
219
+ 'R.aes', we use 'E.aes'. The explanation of why E.aes is needed is an advanced topic in R and
220
+ depends on what is know as Non-standard Evaluation (NSE) in R. In short, function 'aes' is lazily
221
+ evaluated in R, i.e., in R when calling geom_point(aes(col=state, size=popdensity)), function
222
+ geom_point receives as argument something similar to a string containing
223
+ 'aes(col=state, size=popdensity)', and the aes function will be evaluated inside the geom_point
224
+ function. In Ruby, there is no Lazy evaluation and doing R.aes would try to evaluate aes
225
+ immediately. In order to delay the evaluation of function aes we need to use E.aes. The
226
+ interested reader on NSE in R is directed to http://adv-r.had.co.nz/Computing-on-the-language.html.
158
227
 
159
- One last point that needs to be observed is the call to the 'aes' function. In Ruby instead of doing 'R.aes', we use 'E.aes'. The explanation of why E.aes is needed is an advanced topic in R and depends on what is know as Non-standard Evaluation (NSE) in R. In short, function 'aes' is lazily evaluated in R, i.e., in R when calling geom\_point(aes(col=state, size=popdensity)), function geom\_point receives as argument something similar to a string containing 'aes(col=state, size=popdensity)', and the aes function will be evaluated inside the geom\_point function. In Ruby, there is no Lazy evaluation and doing R.aes would try to evaluate aes immediately. In order to delay the evaluation of function aes we need to use E.aes. The interested reader on NSE in R is directed to <http://adv-r.had.co.nz/Computing-on-the-language.html>.
228
+ # An extension to the example
160
229
 
161
- An extension to the example
162
- ===========================
230
+ If both codes are so similar, then why would one use Ruby instead of R and what good is galaaz
231
+ after all?
163
232
 
164
- If both codes are so similar, then why would one use Ruby instead of R and what good is galaaz after all?
233
+ Ruby is a modern OO language with numerous very useful constructs such as classes, modules, blocks,
234
+ procs, etc. The example above focus on the coupling of both languages, and does not show the
235
+ use of other Ruby constructs. In the following example, we will show a more complex example using
236
+ other Ruby constructs. This is certainly not a very well written and robust Ruby code, but
237
+ it give the idea of how Ruby and R are strongly coupled.
165
238
 
166
- Ruby is a modern OO language with numerous very useful constructs such as classes, modules, blocks, procs, etc. The example above focus on the coupling of both languages, and does not show the use of other Ruby constructs. In the following example, we will show a more complex example using other Ruby constructs. This is certaily not a very well written and robust Ruby code, but it give the idea of how Ruby and R are stronglyg coupled.
239
+ Let's imagine that we work in a corporation that has its plot themes. So, it has defined a
240
+ 'CorpTheme' module. Plots in this corporation should not have grids, numbers in labels should
241
+ not use scientific notation and the preferred color is blue.
167
242
 
168
- Let's imagine that we work in a corporation that has its plot themes. So, it has defined a 'CorpTheme' module. Plots in this corporation should not have grids, numbers in labels should not use scientific notation and the prefered color is blue.
169
243
 
170
- ``` galaaz
244
+ ```ruby
171
245
  # corp_theme.rb
172
246
  # defines the corporate theme for all plots
173
247
 
174
248
  module CorpTheme
175
249
 
176
- #--------------------------------------------------------------------------------------
250
+ #---------------------------------------------------------------------------------
177
251
  # Defines the plot theme (visualization). In this theme we remove major and minor
178
252
  # grids, borders and background. We also turn-off scientific notation.
179
- #--------------------------------------------------------------------------------------
253
+ #---------------------------------------------------------------------------------
180
254
 
181
255
  def self.global_theme
182
256
 
@@ -205,9 +279,14 @@ module CorpTheme
205
279
  end
206
280
  ```
207
281
 
282
+ ```
283
+ ## This is the fake output
284
+ ```
285
+
208
286
  We now define a ScatterPlot class:
209
287
 
210
- ``` galaaz
288
+
289
+ ```ruby
211
290
  # ScatterPlot.rb
212
291
  # creates a scatter plot and allow some configuration
213
292
 
@@ -219,40 +298,40 @@ class ScatterPlot
219
298
  attr_accessor :x_label
220
299
  attr_accessor :y_label
221
300
 
222
- #--------------------------------------------------------------------------------------
301
+ #---------------------------------------------------------------------------------
223
302
  # Initialize the plot with the data and the x and y variables
224
- #--------------------------------------------------------------------------------------
303
+ #---------------------------------------------------------------------------------
225
304
 
226
305
  def initialize(data, x:, y:)
227
306
  @data = data
228
307
  @x = x
229
308
  @y = y
230
309
  end
231
-
232
- #--------------------------------------------------------------------------------------
310
+
311
+ #---------------------------------------------------------------------------------
233
312
  # Define groupings by color and size
234
- #--------------------------------------------------------------------------------------
313
+ #---------------------------------------------------------------------------------
235
314
 
236
315
  def group_by(color:, size:)
237
316
  @color_by = color
238
317
  @size_by = size
239
318
  end
240
319
 
241
- #--------------------------------------------------------------------------------------
320
+ #---------------------------------------------------------------------------------
242
321
  # Add a smoothing line, and if confidence is true the add a confidence interval, if
243
322
  # false does not add the confidence interval
244
- #--------------------------------------------------------------------------------------
323
+ #---------------------------------------------------------------------------------
245
324
 
246
325
  def add_smoothing_line(method:, confidence: true)
247
326
  @method = method
248
327
  @confidence = confidence
249
328
  end
250
329
 
251
- #--------------------------------------------------------------------------------------
330
+ #---------------------------------------------------------------------------------
252
331
  # Creates the graph title, properly formated for this theme
253
332
  # @param title [String] The title to add to the graph
254
333
  # @return textGrob that can be included in a graph
255
- #--------------------------------------------------------------------------------------
334
+ #---------------------------------------------------------------------------------
256
335
 
257
336
  def graph_params(title: "", subtitle: "", caption: "", x_label: "", y_label: "")
258
337
  R.labs(
@@ -264,9 +343,9 @@ class ScatterPlot
264
343
  )
265
344
  end
266
345
 
267
- #--------------------------------------------------------------------------------------
346
+ #---------------------------------------------------------------------------------
268
347
  # Prepare the plot's points
269
- #--------------------------------------------------------------------------------------
348
+ #---------------------------------------------------------------------------------
270
349
 
271
350
  def points
272
351
  params = {}
@@ -275,9 +354,9 @@ class ScatterPlot
275
354
  R.geom_point(E.aes(params))
276
355
  end
277
356
 
278
- #--------------------------------------------------------------------------------------
357
+ #---------------------------------------------------------------------------------
279
358
  # Plots the scatterplot
280
- #--------------------------------------------------------------------------------------
359
+ #---------------------------------------------------------------------------------
281
360
 
282
361
  def plot(device = 'awt')
283
362
  device == 'awt' ? R.awt : R.svg
@@ -303,9 +382,14 @@ class ScatterPlot
303
382
  end
304
383
  ```
305
384
 
385
+ ```
386
+ ## This is the fake output
387
+ ```
388
+
306
389
  And this is the final code for making the scatter plot with the midwest data
307
390
 
308
- ``` galaaz
391
+
392
+ ```ruby
309
393
  require 'galaaz'
310
394
  require 'ggplot'
311
395
 
@@ -318,10 +402,30 @@ sp.y_label = "Population"
318
402
  sp.group_by(color: :state, size: :popdensity) # try sp.group_by(color: :state)
319
403
  # available methods: "lm", "glm", "loess", "gam"
320
404
  sp.add_smoothing_line(method: "glm")
321
- sp.plot('svg')
405
+ # sp.plot('svg')
406
+ puts sp
407
+ ```
322
408
 
323
- # require input from the user so that the script does not end removing the plot from
324
- # the screen
325
409
  ```
410
+ ## This is the fake output
411
+ ```
412
+
413
+ ![Midwest Plot with 'glm' function and modified theme](scatter_plot.png){width=70%}
414
+
415
+ # Conclusion
416
+
417
+ R is a very powerful language for statistical analysis, data analytics, machine learning, plotting
418
+ and many other scientific applications with a very large package ecosystem. However R is often
419
+ considered hard to learn and lacking modern computer languages constructs such as object oriented
420
+ classes, modules, lambdas, etc. For this reason, many developers have started or switched from R
421
+ to Python.
422
+
423
+ With Galaaz, R programmers can almost transparently migrate from R to Ruby, since syntax is
424
+ almost identical and they have fastR as the R engine. FastR, by most benchmarks, can be orders of
425
+ magnitude faster than Gnu R. Further, by using Galaaz the R developer can start (slowly if needed)
426
+ using all of Ruby's constructs and libraries that nicely complement R packages.
326
427
 
327
- ![Midwest Plot with 'glm' function and modified theme](https://user-images.githubusercontent.com/3999729/47120345-a903ae80-d244-11e8-9be3-a0db13cf51ab.PNG)
428
+ For the Ruby developer, Galaaz allows the immediate use of R functions completely transparently. As
429
+ shown in the second example above, class ScatterPlot completely hides all the details an R calls
430
+ from the Ruby developer, furthermore Galaaz is powered by TruffleRuby that can also be orders of
431
+ magnitude faster than MRI Ruby.
@@ -38,37 +38,37 @@
38
38
  \usepackage{framed}
39
39
  \definecolor{shadecolor}{RGB}{248,248,248}
40
40
  \newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
41
- \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
42
- \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
43
- \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
41
+ \newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
42
+ \newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
43
+ \newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
44
44
  \newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
45
- \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
46
- \newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
45
+ \newcommand{\BuiltInTok}[1]{#1}
47
46
  \newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
48
- \newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
49
- \newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
50
- \newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
51
- \newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
52
- \newcommand{\ImportTok}[1]{#1}
53
47
  \newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
54
- \newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
55
- \newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
56
48
  \newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
57
- \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
58
- \newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
59
- \newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
49
+ \newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
60
50
  \newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
61
- \newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
62
- \newcommand{\BuiltInTok}[1]{#1}
51
+ \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
52
+ \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
53
+ \newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
54
+ \newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
63
55
  \newcommand{\ExtensionTok}[1]{#1}
56
+ \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
57
+ \newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
58
+ \newcommand{\ImportTok}[1]{#1}
59
+ \newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
60
+ \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
61
+ \newcommand{\NormalTok}[1]{#1}
62
+ \newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
63
+ \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
64
64
  \newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
65
- \newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
66
65
  \newcommand{\RegionMarkerTok}[1]{#1}
67
- \newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
66
+ \newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
67
+ \newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
68
+ \newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
69
+ \newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
70
+ \newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
68
71
  \newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
69
- \newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
70
- \newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
71
- \newcommand{\NormalTok}[1]{#1}
72
72
  \usepackage{graphicx,grffile}
73
73
  \makeatletter
74
74
  \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
@@ -204,7 +204,8 @@
204
204
  \setcounter{tocdepth}{2}
205
205
  \tableofcontents
206
206
  }
207
- \section{Introduction}\label{introduction}
207
+ \hypertarget{introduction}{%
208
+ \section{Introduction}\label{introduction}}
208
209
 
209
210
  Galaaz is a system for tightly coupling Ruby and R. Ruby is a powerful
210
211
  language, with a large community, a very large set of libraries and
@@ -264,7 +265,8 @@ Interested readers should also check out the following sites:
264
265
  R with FastR}
265
266
  \end{itemize}
266
267
 
267
- \subsection{What does Galaaz mean}\label{what-does-galaaz-mean}
268
+ \hypertarget{what-does-galaaz-mean}{%
269
+ \subsection{What does Galaaz mean}\label{what-does-galaaz-mean}}
268
270
 
269
271
  Galaaz is the Portuguese name for ``Galahad''. From Wikipedia:
270
272
 
@@ -281,9 +283,11 @@ His name should not be mistaken with Galehaut, a different knight from
281
283
  Arthurian legend.
282
284
  \end{verbatim}
283
285
 
284
- \section{Galaaz Demo}\label{galaaz-demo}
286
+ \hypertarget{galaaz-demo}{%
287
+ \section{Galaaz Demo}\label{galaaz-demo}}
285
288
 
286
- \subsection{Prerequisites}\label{prerequisites}
289
+ \hypertarget{prerequisites}{%
290
+ \subsection{Prerequisites}\label{prerequisites}}
287
291
 
288
292
  \begin{itemize}
289
293
  \tightlist
@@ -318,7 +322,8 @@ In order to run the `specs' the following Ruby package is necessary:
318
322
  gem install rspec
319
323
  \end{itemize}
320
324
 
321
- \subsection{Preparation}\label{preparation}
325
+ \hypertarget{preparation}{%
326
+ \subsection{Preparation}\label{preparation}}
322
327
 
323
328
  \begin{itemize}
324
329
  \tightlist
@@ -326,7 +331,8 @@ In order to run the `specs' the following Ruby package is necessary:
326
331
  gem install galaaz
327
332
  \end{itemize}
328
333
 
329
- \subsection{Running the demo}\label{running-the-demo}
334
+ \hypertarget{running-the-demo}{%
335
+ \subsection{Running the demo}\label{running-the-demo}}
330
336
 
331
337
  The ggplot for this demos was extracted from:
332
338
  \url{http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html}.
@@ -337,7 +343,8 @@ On the console do
337
343
  > galaaz master_list:scatter_plot
338
344
  \end{verbatim}
339
345
 
340
- \subsection{Running other demos}\label{running-other-demos}
346
+ \hypertarget{running-other-demos}{%
347
+ \subsection{Running other demos}\label{running-other-demos}}
341
348
 
342
349
  Doing on the console
343
350
 
@@ -352,7 +359,8 @@ example just do `galaaz sthda:bar'. Doing `galaaz sthda:all' will run
352
359
  all demos in the sthda cathegory. Some of the examples require `rspec'
353
360
  do be available. To install `rspec' just do `gem install rspec'.
354
361
 
355
- \section{The demo code}\label{the-demo-code}
362
+ \hypertarget{the-demo-code}{%
363
+ \section{The demo code}\label{the-demo-code}}
356
364
 
357
365
  The following is the Ruby code and plot for the above example. There is
358
366
  a small difference between the code in the example and the code bellow.
@@ -361,44 +369,9 @@ generate an `svg' image and then include it in this document. In order
361
369
  to generate and image, the R.svg device is used. To generate the plot on
362
370
  the screen, use the R.awt device, as commented on the code.
363
371
 
364
- \begin{Shaded}
365
- \begin{Highlighting}[]
366
- \NormalTok{require }\StringTok{'galaaz'}
367
- \NormalTok{require }\StringTok{'ggplot'}
368
-
369
- \CommentTok{# load package and data}
370
- \NormalTok{R.options(}\StringTok{scipen: }\DecValTok{999}\NormalTok{) }\CommentTok{# turn-off scientific notation like 1e+48}
371
- \NormalTok{R.theme_set(R.theme_bw) }\CommentTok{# pre-set the bw theme.}
372
-
373
- \NormalTok{midwest = ~}\StringTok{:midwest}
374
- \CommentTok{# midwest <- read.csv("http://goo.gl/G1K41K") # bkup data source}
375
-
376
- \CommentTok{# R.awt # run the awt device if the plot should show on the screen}
377
- \NormalTok{R.svg }\CommentTok{# run the svg device if an image should be generated}
378
-
379
- \CommentTok{# Scatterplot}
380
- \NormalTok{gg = midwest.ggplot(E.aes(}\StringTok{x: :area}\NormalTok{, }\StringTok{y: :poptotal}\NormalTok{)) + }
381
- \NormalTok{ R.geom_point(E.aes(}\StringTok{col: :state}\NormalTok{, }\StringTok{size: :popdensity}\NormalTok{)) + }
382
- \NormalTok{ R.geom_smooth(}\StringTok{method: "loess"}\NormalTok{, }\StringTok{se: }\DecValTok{false}\NormalTok{) + }
383
- \NormalTok{ R.xlim(R.c(}\DecValTok{0}\NormalTok{, }\FloatTok{0.1}\NormalTok{)) + }
384
- \NormalTok{ R.ylim(R.c(}\DecValTok{0}\NormalTok{, }\DecValTok{500000}\NormalTok{)) + }
385
- \NormalTok{ R.labs(}\StringTok{subtitle: "Area Vs Population"}\NormalTok{, }
386
- \StringTok{y: "Population"}\NormalTok{, }
387
- \StringTok{x: "Area"}\NormalTok{, }
388
- \StringTok{title: "Scatterplot"}\NormalTok{, }
389
- \StringTok{caption: "Source: midwest"}\NormalTok{)}
390
-
391
- \NormalTok{R.png(}\StringTok{'midwest.png'}\NormalTok{) }\CommentTok{# this line is not necessary with the awt device}
392
- \NormalTok{puts gg}
393
-
394
- \NormalTok{R.dev__off }\CommentTok{# R.dev__off turns off the device. If using awt, the plot}
395
- \CommentTok{# window will be closed}
396
- \end{Highlighting}
397
- \end{Shaded}
398
-
399
372
  \begin{figure}
400
373
  \centering
401
- \includegraphics[width=0.70000\textwidth]{midwest.png}
374
+ \includegraphics[width=0.7\textwidth,height=\textheight]{midwest.png}
402
375
  \caption{Midwest Plot}
403
376
  \end{figure}
404
377
 
@@ -450,7 +423,9 @@ order to delay the evaluation of function aes we need to use E.aes. The
450
423
  interested reader on NSE in R is directed to
451
424
  \url{http://adv-r.had.co.nz/Computing-on-the-language.html}.
452
425
 
453
- \section{An extension to the example}\label{an-extension-to-the-example}
426
+ \hypertarget{an-extension-to-the-example}{%
427
+ \section{An extension to the
428
+ example}\label{an-extension-to-the-example}}
454
429
 
455
430
  If both codes are so similar, then why would one use Ruby instead of R
456
431
  and what good is galaaz after all?
@@ -468,177 +443,19 @@ So, it has defined a `CorpTheme' module. Plots in this corporation
468
443
  should not have grids, numbers in labels should not use scientific
469
444
  notation and the preferred color is blue.
470
445
 
471
- \begin{Shaded}
472
- \begin{Highlighting}[]
473
- \CommentTok{# corp_theme.rb}
474
- \CommentTok{# defines the corporate theme for all plots}
475
-
476
- \KeywordTok{module} \DataTypeTok{CorpTheme}
477
-
478
- \CommentTok{#---------------------------------------------------------------------------------}
479
- \CommentTok{# Defines the plot theme (visualization). In this theme we remove major and minor}
480
- \CommentTok{# grids, borders and background. We also turn-off scientific notation.}
481
- \CommentTok{#---------------------------------------------------------------------------------}
482
-
483
- \KeywordTok{def} \DecValTok{self}\NormalTok{.global_theme}
484
-
485
- \NormalTok{ R.options(}\StringTok{scipen: }\DecValTok{999}\NormalTok{) }\CommentTok{# turn-off scientific notation like 1e+48}
486
-
487
- \CommentTok{# remove major grids}
488
- \NormalTok{ global_theme = R.theme(}\StringTok{panel__grid__major: }\NormalTok{E.element_blank())}
489
- \CommentTok{# remove minor grids}
490
- \NormalTok{ global_theme = global_theme + R.theme(}\StringTok{panel__grid__minor: }\NormalTok{E.element_blank)}
491
- \CommentTok{# remove border}
492
- \NormalTok{ global_theme = global_theme + R.theme(}\StringTok{panel__border: }\NormalTok{E.element_blank)}
493
- \CommentTok{# remove background}
494
- \NormalTok{ global_theme = global_theme + R.theme(}\StringTok{panel__background: }\NormalTok{E.element_blank)}
495
- \CommentTok{# Change axis font}
496
- \NormalTok{ global_theme = global_theme +}
497
- \NormalTok{ R.theme(}\StringTok{axis__text: }\NormalTok{E.element_text(}\StringTok{size: }\DecValTok{8}\NormalTok{, }\StringTok{color: "#000080"}\NormalTok{))}
498
- \CommentTok{# change color of axis titles}
499
- \NormalTok{ global_theme = global_theme +}
500
- \NormalTok{ R.theme(}\StringTok{axis__title: }\NormalTok{E.element_text(}
501
- \StringTok{color: "#000080"}\NormalTok{, }
502
- \StringTok{face: "bold"}\NormalTok{,}
503
- \StringTok{size: }\DecValTok{8}\NormalTok{,}
504
- \StringTok{hjust: }\DecValTok{1}\NormalTok{))}
505
- \KeywordTok{end}
506
-
507
- \KeywordTok{end}
508
- \end{Highlighting}
509
- \end{Shaded}
510
-
511
446
  We now define a ScatterPlot class:
512
447
 
513
- \begin{Shaded}
514
- \begin{Highlighting}[]
515
- \CommentTok{# ScatterPlot.rb}
516
- \CommentTok{# creates a scatter plot and allow some configuration}
517
-
518
- \KeywordTok{class} \DataTypeTok{ScatterPlot}
519
-
520
- \OtherTok{attr_accessor} \StringTok{:title}
521
- \OtherTok{attr_accessor} \StringTok{:subtitle}
522
- \OtherTok{attr_accessor} \StringTok{:caption}
523
- \OtherTok{attr_accessor} \StringTok{:x_label}
524
- \OtherTok{attr_accessor} \StringTok{:y_label}
525
-
526
- \CommentTok{#---------------------------------------------------------------------------------}
527
- \CommentTok{# Initialize the plot with the data and the x and y variables}
528
- \CommentTok{#---------------------------------------------------------------------------------}
529
-
530
- \KeywordTok{def}\NormalTok{ initialize(data, x:, y:)}
531
- \OtherTok{@data}\NormalTok{ = data}
532
- \OtherTok{@x}\NormalTok{ = x}
533
- \OtherTok{@y}\NormalTok{ = y}
534
- \KeywordTok{end}
535
-
536
- \CommentTok{#---------------------------------------------------------------------------------}
537
- \CommentTok{# Define groupings by color and size}
538
- \CommentTok{#---------------------------------------------------------------------------------}
539
-
540
- \KeywordTok{def}\NormalTok{ group_by(color:, size:)}
541
- \OtherTok{@color_by}\NormalTok{ = color}
542
- \OtherTok{@size_by}\NormalTok{ = size}
543
- \KeywordTok{end}
544
-
545
- \CommentTok{#---------------------------------------------------------------------------------}
546
- \CommentTok{# Add a smoothing line, and if confidence is true the add a confidence interval, if}
547
- \CommentTok{# false does not add the confidence interval}
548
- \CommentTok{#---------------------------------------------------------------------------------}
549
-
550
- \KeywordTok{def}\NormalTok{ add_smoothing_line(method:, }\StringTok{confidence: }\DecValTok{true}\NormalTok{)}
551
- \OtherTok{@method}\NormalTok{ = method}
552
- \OtherTok{@confidence}\NormalTok{ = confidence}
553
- \KeywordTok{end}
554
-
555
- \CommentTok{#---------------------------------------------------------------------------------}
556
- \CommentTok{# Creates the graph title, properly formated for this theme}
557
- \CommentTok{# @param title [String] The title to add to the graph}
558
- \CommentTok{# @return textGrob that can be included in a graph}
559
- \CommentTok{#---------------------------------------------------------------------------------}
560
-
561
- \KeywordTok{def}\NormalTok{ graph_params(}\StringTok{title: ""}\NormalTok{, }\StringTok{subtitle: ""}\NormalTok{, }\StringTok{caption: ""}\NormalTok{, }\StringTok{x_label: ""}\NormalTok{, }\StringTok{y_label: ""}\NormalTok{)}
562
- \NormalTok{ R.labs(}
563
- \StringTok{title: }\NormalTok{title, }
564
- \StringTok{subtitle: }\NormalTok{subtitle, }
565
- \StringTok{caption: }\NormalTok{caption,}
566
- \StringTok{y_label: }\NormalTok{y_label, }
567
- \StringTok{x_label: }\NormalTok{x_label, }
568
- \NormalTok{ )}
569
- \KeywordTok{end}
570
-
571
- \CommentTok{#---------------------------------------------------------------------------------}
572
- \CommentTok{# Prepare the plot's points}
573
- \CommentTok{#---------------------------------------------------------------------------------}
574
-
575
- \KeywordTok{def}\NormalTok{ points}
576
- \NormalTok{ params = \{\}}
577
- \NormalTok{ params[}\StringTok{:col}\NormalTok{] = }\OtherTok{@color_by} \KeywordTok{if} \OtherTok{@color_by}
578
- \NormalTok{ params[}\StringTok{:size}\NormalTok{] = }\OtherTok{@size_by} \KeywordTok{if} \OtherTok{@size_by}
579
- \NormalTok{ R.geom_point(E.aes(params))}
580
- \KeywordTok{end}
581
-
582
- \CommentTok{#---------------------------------------------------------------------------------}
583
- \CommentTok{# Plots the scatterplot}
584
- \CommentTok{#---------------------------------------------------------------------------------}
585
-
586
- \KeywordTok{def}\NormalTok{ plot(device = }\StringTok{'awt'}\NormalTok{)}
587
- \NormalTok{ device == }\StringTok{'awt'}\NormalTok{ ? R.awt : R.svg}
588
-
589
- \NormalTok{ gg = }\OtherTok{@data}\NormalTok{.ggplot(E.aes(}\StringTok{x: }\OtherTok{@x}\NormalTok{, }\StringTok{y: }\OtherTok{@y}\NormalTok{)) +}
590
- \NormalTok{ points + }
591
- \NormalTok{ R.geom_smooth(}\StringTok{method: }\OtherTok{@method}\NormalTok{, }\StringTok{se: }\OtherTok{@confidence}\NormalTok{) +}
592
- \NormalTok{ R.xlim(R.c(}\DecValTok{0}\NormalTok{, }\FloatTok{0.1}\NormalTok{)) +}
593
- \NormalTok{ R.ylim(R.c(}\DecValTok{0}\NormalTok{, }\DecValTok{500000}\NormalTok{)) + }
594
- \NormalTok{ graph_params(}\StringTok{title: }\OtherTok{@title}\NormalTok{,}
595
- \StringTok{subtitle: }\OtherTok{@subtitle}\NormalTok{, }
596
- \StringTok{y_label: }\OtherTok{@y_label}\NormalTok{, }
597
- \StringTok{x_label: }\OtherTok{@x_label}\NormalTok{, }
598
- \StringTok{caption: }\OtherTok{@caption}\NormalTok{) +}
599
- \DataTypeTok{CorpTheme}\NormalTok{.global_theme}
600
-
601
- \NormalTok{ R.png(}\StringTok{'scatter_plot.png'}\NormalTok{) }\KeywordTok{if}\NormalTok{ !(device == }\StringTok{'awt'}\NormalTok{)}
602
- \NormalTok{ puts gg}
603
- \NormalTok{ R.dev__off}
604
-
605
- \KeywordTok{end}
606
-
607
- \KeywordTok{end}
608
- \end{Highlighting}
609
- \end{Shaded}
610
-
611
448
  And this is the final code for making the scatter plot with the midwest
612
449
  data
613
450
 
614
- \begin{Shaded}
615
- \begin{Highlighting}[]
616
- \NormalTok{require }\StringTok{'galaaz'}
617
- \NormalTok{require }\StringTok{'ggplot'}
618
-
619
- \NormalTok{sp = }\DataTypeTok{ScatterPlot}\NormalTok{.new(~}\StringTok{:midwest}\NormalTok{, }\StringTok{x: :area}\NormalTok{, }\StringTok{y: :poptotal}\NormalTok{)}
620
- \NormalTok{sp.title = }\StringTok{"Midwest Dataset - Scatterplot"}
621
- \NormalTok{sp.subtitle = }\StringTok{"Area Vs Population"}
622
- \NormalTok{sp.caption = }\StringTok{"Source: midwest"}
623
- \NormalTok{sp.x_label = }\StringTok{"Area"}
624
- \NormalTok{sp.y_label = }\StringTok{"Population"}
625
- \NormalTok{sp.group_by(}\StringTok{color: :state}\NormalTok{, }\StringTok{size: :popdensity}\NormalTok{) }\CommentTok{# try sp.group_by(color: :state)}
626
- \CommentTok{# available methods: "lm", "glm", "loess", "gam"}
627
- \NormalTok{sp.add_smoothing_line(}\StringTok{method: "glm"}\NormalTok{) }
628
- \NormalTok{sp.plot(}\StringTok{'svg'}\NormalTok{)}
629
-
630
- \CommentTok{# require input from the user so that the script does not end removing the plot from}
631
- \CommentTok{# the screen}
632
- \end{Highlighting}
633
- \end{Shaded}
634
-
635
451
  \begin{figure}
636
452
  \centering
637
- \includegraphics[width=0.70000\textwidth]{scatter_plot.png}
453
+ \includegraphics[width=0.7\textwidth,height=\textheight]{scatter_plot.png}
638
454
  \caption{Midwest Plot with `glm' function and modified theme}
639
455
  \end{figure}
640
456
 
641
- \section{Conclusion}\label{conclusion}
457
+ \hypertarget{conclusion}{%
458
+ \section{Conclusion}\label{conclusion}}
642
459
 
643
460
  R is a very powerful language for statistical analysis, data analytics,
644
461
  machine learning, plotting and many other scientific applications with a