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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ad876f56c2ea9e6fdc91cf83d78f6fe244d8efa
4
- data.tar.gz: ac59d99327b8c03d9f10ead0901f9f3687ec68e7
3
+ metadata.gz: 567380b5c235ab363a1b4c5848e06126a0ee635b
4
+ data.tar.gz: b0d4735743f9f6f50af6e9231e9bad2001bf2e65
5
5
  SHA512:
6
- metadata.gz: e496ee01ab1f286ed256c5821838c7d4f8e23e627b2b3721920abb103f276e3c82f727eb40b4d8b89f9524c4e2a3040f9fad7573eeba052388ca87b2e059af88
7
- data.tar.gz: 11aa21a756cb3ad60680d807253c577153b2fe2f88e93dc0afefe1f820399444374d7cba69346e24cd887b73c0d049560b5efa1b42e9d8c5f55b807b45ddda64
6
+ metadata.gz: b6e9847e52df71021cbcc4e67e21bb5f15cde4e85bf52def332ef5acb0acab23542db97a7907bab6ec00ee5f038c22412e250e1af7c317ab99ceb6bb7007011b
7
+ data.tar.gz: 1d2e3694c81ba8de5f06ded79c5d04e3d987d97680cc898d51aa5fadfc4f5ef3e45741164a106680dd6f5df9f55461d526f5d88c4ff500eb68254c0da5728eaa
data/README.md CHANGED
@@ -1,325 +1,751 @@
1
- Introduction
2
- ============
1
+ ---
2
+ title: "Galaaz Manual"
3
+ subtitle: "How to tightly couple Ruby and R in GraalVM"
4
+ author: "Rodrigo Botafogo"
5
+ tags: [Galaaz, Ruby, R, TruffleRuby, FastR, GraalVM, ggplot2]
6
+ date: "2019"
7
+ output:
8
+ html_document:
9
+ self_contained: true
10
+ keep_md: true
11
+ md_document:
12
+ variant: markdown_github
13
+ pdf_document:
14
+ includes:
15
+ in_header: "../../sty/galaaz.sty"
16
+ keep_tex: yes
17
+ number_sections: yes
18
+ toc: true
19
+ toc_depth: 2
20
+ fontsize: 11pt
21
+ ---
3
22
 
4
- 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.
5
23
 
6
- 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:
7
24
 
8
- GraalVM is a universal virtual machine for running applications written in JavaScript,
9
- Python 3, Ruby, R, JVM-based languages like Java, Scala, Kotlin, and LLVM-based languages
10
- such as C and C++.
11
25
 
12
- GraalVM removes the isolation between programming languages and enables interoperability in a
13
- shared runtime. It can run either standalone or in the context of OpenJDK, Node.js,
14
- Oracle Database, or MySQL.
26
+ # Introduction
15
27
 
16
- GraalVM allows you to write polyglot applications with a seamless way to pass values from one
17
- language to another. With GraalVM there is no copying or marshalling necessary as it is with
18
- other polyglot systems. This lets you achieve high performance when language boundaries are
19
- crossed. Most of the time there is no additional cost for crossing a language boundary at all.
28
+ Galaaz is a system for tightly coupling Ruby and R. Ruby is a powerful language, with a large
29
+ community, a very large set of libraries and great for web development. However, it lacks
30
+ libraries for data science, statistics, scientific plotting and machine learning. On the
31
+ other hand, R is considered one of the most powerful languages for solving all of the above
32
+ problems. Maybe the strongest competitor to R is Python with libraries such as NumPy,
33
+ Panda, SciPy, SciKit-Learn and a couple more.
20
34
 
21
- Often developers have to make uncomfortable compromises that require them to rewrite
22
- their software in other languages. For example:
35
+ # System Compatibility
23
36
 
24
- * “That library is not available in my language. I need to rewrite it.”
25
- * “That language would be the perfect fit for my problem, but we cannot run it in our environment.”
26
- * “That problem is already solved in my language, but the language is too slow.”
37
+ * Oracle Linux 7
38
+ * Ubuntu 18.04 LTS
39
+ * Ubuntu 16.04 LTS
40
+ * Fedora 28
41
+ * macOS 10.14 (Mojave)
42
+ * macOS 10.13 (High Sierra)
27
43
 
28
- With GraalVM we aim to allow developers to freely choose the right language for the task at
29
- hand without making compromises.
44
+ # Dependencies
30
45
 
31
- What does Galaaz mean
32
- ---------------------
46
+ * TruffleRuby
47
+ * FastR
33
48
 
34
- Galaaz is the Portuguese name for "Galahad". From Wikipedia:
35
49
 
36
- Sir Galahad (/ˈɡæləhæd/; sometimes referred to as Galeas /ɡəˈliːəs/ or Galath /ˈɡæləθ/),
37
- in Arthurian legend, is a knight of King Arthur's Round Table and one of the three
38
- achievers of the Holy Grail. He is the illegitimate son of Sir Lancelot and Elaine of
39
- Corbenic, and is renowned for his gallantry and purity as the most perfect of all knights.
40
- Emerging quite late in the medieval Arthurian tradition, Sir Galahad first appears in the
41
- Lancelot–Grail cycle, and his story is taken up in later works such as the Post-Vulgate
42
- Cycle and Sir Thomas Malory's Le Morte d'Arthur. His name should not be mistaken with
43
- Galehaut, a different knight from Arthurian legend.
50
+ # Installation
44
51
 
45
- Galaaz Demo
46
- ===========
52
+ * Install GrallVM (http://www.graalvm.org/)
53
+ * Install Ruby (gu install Ruby)
54
+ * Install FastR (gu install R)
55
+ * Install rake if you want to run the specs and examples (gem install rake)
47
56
 
48
- Prerequisites
49
- -------------
57
+ # Usage
50
58
 
51
- - GraalVM (>= rc7)
52
- - TruffleRuby
53
- - FastR
59
+ * Interactive shell: use 'gstudio' on the command line
54
60
 
55
- The following R packages will be automatically installed when necessary, but could be installed prior to the demo if desired:
61
+ > gstudio
56
62
 
57
- - ggplot2
58
- - gridExtra
59
63
 
60
- 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.
64
+ ```ruby
65
+ vec = R.c(1, 2, 3, 4)
66
+ puts vec
67
+ ```
61
68
 
62
- In order to run the 'specs' the following Ruby package is necessary:
69
+ ```
70
+ ## [1] 1 2 3 4
71
+ ```
72
+
73
+ * Run all specs
63
74
 
64
- - gem install rspec
75
+ > galaaz specs:all
76
+
77
+ * Run graphics slideshow (80+ graphics)
65
78
 
66
- Preparation
67
- -----------
79
+ > galaaz sthda:all
80
+
81
+ * Run labs from Introduction to Statistical Learning with R
68
82
 
69
- - gem install galaaz
83
+ > galaaz islr:all
70
84
 
71
- Running the demo
72
- ----------------
85
+ * See all available examples
73
86
 
74
- The ggplot for this demos was extracted from: <http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html>.
87
+ > galaaz -T
88
+
89
+ Shows a list with all available executalbe tasks. To execute a task, substitute the
90
+ 'rake' word in the list with 'galaaz'. For instance, the following line shows up
91
+ after 'galaaz -T'
92
+
93
+ rake master_list:scatter_plot # scatter_plot from:....
94
+
95
+ execute
96
+
97
+ > galaaz master_list:scatter_plot
75
98
 
76
- On the console do
99
+ # Basic Types
77
100
 
78
- > galaaz master_list:scatter_plot
101
+ ## Vectors
79
102
 
80
- Running other demos
81
- -------------------
103
+ Vectors can be thought of as contiguous cells containing data. Cells are accessed through
104
+ indexing operations such as x[5]. Galaaz has six basic (‘atomic’) vector types: logical,
105
+ integer, real, complex, string (or character) and raw. The modes and storage modes for the
106
+ different vector types are listed in the following
107
+ table.
82
108
 
83
- Doing on the console
109
+ | typeof | mode | storage.mode |
110
+ |-----------|:---------:|-------------:|
111
+ | logical | logical | logical |
112
+ | integer | numeric | integer |
113
+ | double | numeric | double |
114
+ | complex | complex | comples |
115
+ | character | character | character |
116
+ | raw | raw | raw |
84
117
 
85
- > galaaz -T
118
+ Single numbers, such as 4.2, and strings, such as "four point two" are still vectors, of length
119
+ 1; there are no more basic types. Vectors with length zero are possible (and useful).
120
+ String vectors have mode and storage mode "character". A single element of a character
121
+ vector is often referred to as a character string.
86
122
 
87
- 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'.
123
+ To create a vector the 'c' (concatenate) method from the 'R' module should be used:
88
124
 
89
- The demo code
90
- =============
91
125
 
92
- 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.
126
+ ```ruby
127
+ @vec = R.c(1, 2, 3)
128
+ puts @vec
129
+ ```
93
130
 
94
- ``` truby
95
- require 'galaaz'
96
- require 'ggplot'
131
+ ```
132
+ ## [1] 1 2 3
133
+ ```
97
134
 
98
- # load package and data
99
- R.options(scipen: 999) # turn-off scientific notation like 1e+48
100
- R.theme_set(R.theme_bw) # pre-set the bw theme.
101
-
102
- midwest = ~:midwest
103
- # midwest <- read.csv("http://goo.gl/G1K41K") # bkup data source
104
-
105
- # R.awt # run the awt device if the plot should show on the screen
106
- R.svg # run the svg device if an image should be generated
107
-
108
- # Scatterplot
109
- gg = midwest.ggplot(E.aes(x: :area, y: :poptotal)) +
110
- R.geom_point(E.aes(col: :state, size: :popdensity)) +
111
- R.geom_smooth(method: "loess", se: false) +
112
- R.xlim(R.c(0, 0.1)) +
113
- R.ylim(R.c(0, 500000)) +
114
- R.labs(subtitle: "Area Vs Population",
115
- y: "Population",
116
- x: "Area",
117
- title: "Scatterplot",
118
- caption: "Source: midwest")
119
-
120
- R.png('midwest.png') # this line is not necessary with the awt device
121
- puts gg
135
+ Lets take a look at the type, mode and storage.mode of our vector @vec. In order to print
136
+ this out, we are creating a data frame 'df' and printing it out. A data frame, for those
137
+ not familiar with it, it basically a table. Here we create the data frame and add the
138
+ column name by passing named parameters for each column, such as 'typeof:', 'mode:' and
139
+ 'storage__mode'. You should also note here that the double underscore is converted to a '.'.
140
+
141
+ In R, the method used to create a data frame is 'data.frame', in Galaaz we use 'data__frame'.
122
142
 
123
- R.dev__off # R.dev__off turns off the device. If using awt, the plot
124
- # window will be closed
143
+
144
+ ```ruby
145
+ df = R.data__frame(typeof: @vec.typeof, mode: @vec.mode, storage__mode: @vec.storage__mode)
146
+ puts df
125
147
  ```
126
148
 
127
- <img src="https://user-images.githubusercontent.com/3999729/46742999-87bc2480-cc7e-11e8-9f16-31c3437e4a58.PNG" alt="Midwest Plot" style="width:70.0%" />
128
-
129
- In R, the code to generate this plot is the following
130
-
131
- ``` r
132
- # install.packages("ggplot2")
133
- # load package and data
134
- options(scipen=999) # turn-off scientific notation like 1e+48
135
- library(ggplot2)
136
- theme_set(theme_bw()) # pre-set the bw theme.
137
- data("midwest", package = "ggplot2")
138
- # midwest <- read.csv("http://goo.gl/G1K41K") # bkup data source
139
-
140
- # Scatterplot
141
- gg <- ggplot(midwest, aes(x=area, y=poptotal)) +
142
- geom_point(aes(col=state, size=popdensity)) +
143
- geom_smooth(method="loess", se=F) +
144
- xlim(c(0, 0.1)) +
145
- ylim(c(0, 500000)) +
146
- labs(subtitle="Area Vs Population",
147
- y="Population",
148
- x="Area",
149
- title="Scatterplot",
150
- caption = "Source: midwest")
151
-
152
- plot(gg)
149
+ ```
150
+ ## typeof mode storage.mode
151
+ ## 1 integer numeric integer
153
152
  ```
154
153
 
155
- 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).
154
+ If you want to create a vector with floating point numbers, then we need at least one of the
155
+ vector's element to be a float, such as 1.0. R users should be careful, since in R a number
156
+ like '1' is converted to float and to have an integer the R developer will use '1L'. Galaaz
157
+ follows normal Ruby rules and the number 1 is an integer and 1.0 is a float.
156
158
 
157
- 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>.
158
159
 
159
- An extension to the example
160
- ===========================
160
+ ```ruby
161
+ @vec = R.c(1.0, 2, 3)
162
+ puts @vec
163
+ ```
161
164
 
162
- If both codes are so similar, then why would one use Ruby instead of R and what good is galaaz after all?
165
+ ```
166
+ ## [1] 1 2 3
167
+ ```
163
168
 
164
- 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.
165
169
 
166
- 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.
170
+ ```ruby
171
+ df = R.data__frame(typeof: @vec.typeof, mode: @vec.mode, storage__mode: @vec.storage__mode)
172
+ outputs df.kable.kable_styling
173
+ ```
167
174
 
168
- ``` truby
169
- # corp_theme.rb
170
- # defines the corporate theme for all plots
171
-
172
- module CorpTheme
175
+ <table class="table" style="margin-left: auto; margin-right: auto;">
176
+ <thead>
177
+ <tr>
178
+ <th style="text-align:left;"> typeof </th>
179
+ <th style="text-align:left;"> mode </th>
180
+ <th style="text-align:left;"> storage.mode </th>
181
+ </tr>
182
+ </thead>
183
+ <tbody>
184
+ <tr>
185
+ <td style="text-align:left;"> double </td>
186
+ <td style="text-align:left;"> numeric </td>
187
+ <td style="text-align:left;"> double </td>
188
+ </tr>
189
+ </tbody>
190
+ </table>
191
+
192
+ In this next example we try to create a vector with a variable 'hello' that has not yet
193
+ being defined. This will raise an exception that is printed out. We get two return blocks,
194
+ the first with a message explaining what went wrong and the second with the full backtrace
195
+ of the error.
196
+
197
+
198
+ ```ruby
199
+ vec = R.c(1, hello, 5)
200
+ ```
173
201
 
174
- #--------------------------------------------------------------------------------------
175
- # Defines the plot theme (visualization). In this theme we remove major and minor
176
- # grids, borders and background. We also turn-off scientific notation.
177
- #--------------------------------------------------------------------------------------
178
-
179
- def self.global_theme
180
-
181
- R.options(scipen: 999) # turn-off scientific notation like 1e+48
182
-
183
- # remove major grids
184
- global_theme = R.theme(panel__grid__major: E.element_blank())
185
- # remove minor grids
186
- global_theme = global_theme + R.theme(panel__grid__minor: E.element_blank)
187
- # remove border
188
- global_theme = global_theme + R.theme(panel__border: E.element_blank)
189
- # remove background
190
- global_theme = global_theme + R.theme(panel__background: E.element_blank)
191
- # Change axis font
192
- global_theme = global_theme +
193
- R.theme(axis__text: E.element_text(size: 8, color: "#000080"))
194
- # change color of axis titles
195
- global_theme = global_theme +
196
- R.theme(axis__title: E.element_text(
197
- color: "#000080",
198
- face: "bold",
199
- size: 8,
200
- hjust: 1))
201
- end
202
-
203
- end
202
+ ```
203
+ ## Message:
204
+ ## undefined local variable or method `hello' for RubyChunk:Class
204
205
  ```
205
206
 
206
- We now define a ScatterPlot class:
207
+ ```
208
+ ## Message:
209
+ ## (eval):1:in `exec_ruby'
210
+ ## /home/rbotafogo/desenv/galaaz/lib/util/exec_ruby.rb:137:in `instance_eval'
211
+ ## /home/rbotafogo/desenv/galaaz/lib/util/exec_ruby.rb:137:in `exec_ruby'
212
+ ## /home/rbotafogo/desenv/galaaz/lib/gknit/ruby_engine.rb:55:in `block in initialize'
213
+ ## /home/rbotafogo/desenv/galaaz/lib/R_interface/ruby_callback.rb:77:in `call'
214
+ ## /home/rbotafogo/desenv/galaaz/lib/R_interface/ruby_callback.rb:77:in `callback'
215
+ ## (eval):3:in `function(...) {\n rb_method(...)'
216
+ ## unknown.r:1:in `in_dir'
217
+ ## unknown.r:1:in `block_exec'
218
+ ## /home/rbotafogo/lib/graalvm-ce-1.0.0-rc12/jre/languages/R/library/knitr/R/block.R:91:in `call_block'
219
+ ## /home/rbotafogo/lib/graalvm-ce-1.0.0-rc12/jre/languages/R/library/knitr/R/block.R:6:in `process_group.block'
220
+ ## /home/rbotafogo/lib/graalvm-ce-1.0.0-rc12/jre/languages/R/library/knitr/R/block.R:3:in `<no source>'
221
+ ## unknown.r:1:in `withCallingHandlers'
222
+ ## unknown.r:1:in `process_file'
223
+ ## unknown.r:1:in `<no source>'
224
+ ## unknown.r:1:in `<no source>'
225
+ ## <REPL>:4:in `<repl wrapper>'
226
+ ## <REPL>:1
227
+ ```
207
228
 
208
- ``` truby
209
- # ScatterPlot.rb
210
- # creates a scatter plot and allow some configuration
211
-
212
- class ScatterPlot
213
229
 
214
- attr_accessor :title
215
- attr_accessor :subtitle
216
- attr_accessor :caption
217
- attr_accessor :x_label
218
- attr_accessor :y_label
219
-
220
- #--------------------------------------------------------------------------------------
221
- # Initialize the plot with the data and the x and y variables
222
- #--------------------------------------------------------------------------------------
223
-
224
- def initialize(data, x:, y:)
225
- @data = data
226
- @x = x
227
- @y = y
228
- end
229
-
230
- #--------------------------------------------------------------------------------------
231
- # Define groupings by color and size
232
- #--------------------------------------------------------------------------------------
233
-
234
- def group_by(color:, size:)
235
- @color_by = color
236
- @size_by = size
237
- end
238
-
239
- #--------------------------------------------------------------------------------------
240
- # Add a smoothing line, and if confidence is true the add a confidence interval, if
241
- # false does not add the confidence interval
242
- #--------------------------------------------------------------------------------------
243
-
244
- def add_smoothing_line(method:, confidence: true)
245
- @method = method
246
- @confidence = confidence
247
- end
248
-
249
- #--------------------------------------------------------------------------------------
250
- # Creates the graph title, properly formated for this theme
251
- # @param title [String] The title to add to the graph
252
- # @return textGrob that can be included in a graph
253
- #--------------------------------------------------------------------------------------
254
-
255
- def graph_params(title: "", subtitle: "", caption: "", x_label: "", y_label: "")
256
- R.labs(
257
- title: title,
258
- subtitle: subtitle,
259
- caption: caption,
260
- y_label: y_label,
261
- x_label: x_label,
262
- )
263
- end
264
-
265
- #--------------------------------------------------------------------------------------
266
- # Prepare the plot's points
267
- #--------------------------------------------------------------------------------------
268
-
269
- def points
270
- params = {}
271
- params[:col] = @color_by if @color_by
272
- params[:size] = @size_by if @size_by
273
- R.geom_point(E.aes(params))
274
- end
275
-
276
- #--------------------------------------------------------------------------------------
277
- # Plots the scatterplot
278
- #--------------------------------------------------------------------------------------
279
-
280
- def plot(device = 'awt')
281
- device == 'awt' ? R.awt : R.svg
282
-
283
- gg = @data.ggplot(E.aes(x: @x, y: @y)) +
284
- points +
285
- R.geom_smooth(method: @method, se: @confidence) +
286
- R.xlim(R.c(0, 0.1)) +
287
- R.ylim(R.c(0, 500000)) +
288
- graph_params(title: @title,
289
- subtitle: @subtitle,
290
- y_label: @y_label,
291
- x_label: @x_label,
292
- caption: @caption) +
293
- CorpTheme.global_theme
294
-
295
- R.png('scatter_plot.png') if !(device == 'awt')
296
- puts gg
297
- R.dev__off
298
-
299
- end
300
-
301
- end
230
+ ```ruby
231
+ outputs (~:mtcars).kable.kable_styling
302
232
  ```
303
233
 
304
- And this is the final code for making the scatter plot with the midwest data
305
-
306
- ``` truby
307
- require 'galaaz'
234
+ <table class="table" style="margin-left: auto; margin-right: auto;">
235
+ <thead>
236
+ <tr>
237
+ <th style="text-align:left;"> </th>
238
+ <th style="text-align:right;"> mpg </th>
239
+ <th style="text-align:right;"> cyl </th>
240
+ <th style="text-align:right;"> disp </th>
241
+ <th style="text-align:right;"> hp </th>
242
+ <th style="text-align:right;"> drat </th>
243
+ <th style="text-align:right;"> wt </th>
244
+ <th style="text-align:right;"> qsec </th>
245
+ <th style="text-align:right;"> vs </th>
246
+ <th style="text-align:right;"> am </th>
247
+ <th style="text-align:right;"> gear </th>
248
+ <th style="text-align:right;"> carb </th>
249
+ </tr>
250
+ </thead>
251
+ <tbody>
252
+ <tr>
253
+ <td style="text-align:left;"> Mazda RX4 </td>
254
+ <td style="text-align:right;"> 21.0 </td>
255
+ <td style="text-align:right;"> 6 </td>
256
+ <td style="text-align:right;"> 160.0 </td>
257
+ <td style="text-align:right;"> 110 </td>
258
+ <td style="text-align:right;"> 3.90 </td>
259
+ <td style="text-align:right;"> 2.620 </td>
260
+ <td style="text-align:right;"> 16.46 </td>
261
+ <td style="text-align:right;"> 0 </td>
262
+ <td style="text-align:right;"> 1 </td>
263
+ <td style="text-align:right;"> 4 </td>
264
+ <td style="text-align:right;"> 4 </td>
265
+ </tr>
266
+ <tr>
267
+ <td style="text-align:left;"> Mazda RX4 Wag </td>
268
+ <td style="text-align:right;"> 21.0 </td>
269
+ <td style="text-align:right;"> 6 </td>
270
+ <td style="text-align:right;"> 160.0 </td>
271
+ <td style="text-align:right;"> 110 </td>
272
+ <td style="text-align:right;"> 3.90 </td>
273
+ <td style="text-align:right;"> 2.875 </td>
274
+ <td style="text-align:right;"> 17.02 </td>
275
+ <td style="text-align:right;"> 0 </td>
276
+ <td style="text-align:right;"> 1 </td>
277
+ <td style="text-align:right;"> 4 </td>
278
+ <td style="text-align:right;"> 4 </td>
279
+ </tr>
280
+ <tr>
281
+ <td style="text-align:left;"> Datsun 710 </td>
282
+ <td style="text-align:right;"> 22.8 </td>
283
+ <td style="text-align:right;"> 4 </td>
284
+ <td style="text-align:right;"> 108.0 </td>
285
+ <td style="text-align:right;"> 93 </td>
286
+ <td style="text-align:right;"> 3.85 </td>
287
+ <td style="text-align:right;"> 2.320 </td>
288
+ <td style="text-align:right;"> 18.61 </td>
289
+ <td style="text-align:right;"> 1 </td>
290
+ <td style="text-align:right;"> 1 </td>
291
+ <td style="text-align:right;"> 4 </td>
292
+ <td style="text-align:right;"> 1 </td>
293
+ </tr>
294
+ <tr>
295
+ <td style="text-align:left;"> Hornet 4 Drive </td>
296
+ <td style="text-align:right;"> 21.4 </td>
297
+ <td style="text-align:right;"> 6 </td>
298
+ <td style="text-align:right;"> 258.0 </td>
299
+ <td style="text-align:right;"> 110 </td>
300
+ <td style="text-align:right;"> 3.08 </td>
301
+ <td style="text-align:right;"> 3.215 </td>
302
+ <td style="text-align:right;"> 19.44 </td>
303
+ <td style="text-align:right;"> 1 </td>
304
+ <td style="text-align:right;"> 0 </td>
305
+ <td style="text-align:right;"> 3 </td>
306
+ <td style="text-align:right;"> 1 </td>
307
+ </tr>
308
+ <tr>
309
+ <td style="text-align:left;"> Hornet Sportabout </td>
310
+ <td style="text-align:right;"> 18.7 </td>
311
+ <td style="text-align:right;"> 8 </td>
312
+ <td style="text-align:right;"> 360.0 </td>
313
+ <td style="text-align:right;"> 175 </td>
314
+ <td style="text-align:right;"> 3.15 </td>
315
+ <td style="text-align:right;"> 3.440 </td>
316
+ <td style="text-align:right;"> 17.02 </td>
317
+ <td style="text-align:right;"> 0 </td>
318
+ <td style="text-align:right;"> 0 </td>
319
+ <td style="text-align:right;"> 3 </td>
320
+ <td style="text-align:right;"> 2 </td>
321
+ </tr>
322
+ <tr>
323
+ <td style="text-align:left;"> Valiant </td>
324
+ <td style="text-align:right;"> 18.1 </td>
325
+ <td style="text-align:right;"> 6 </td>
326
+ <td style="text-align:right;"> 225.0 </td>
327
+ <td style="text-align:right;"> 105 </td>
328
+ <td style="text-align:right;"> 2.76 </td>
329
+ <td style="text-align:right;"> 3.460 </td>
330
+ <td style="text-align:right;"> 20.22 </td>
331
+ <td style="text-align:right;"> 1 </td>
332
+ <td style="text-align:right;"> 0 </td>
333
+ <td style="text-align:right;"> 3 </td>
334
+ <td style="text-align:right;"> 1 </td>
335
+ </tr>
336
+ <tr>
337
+ <td style="text-align:left;"> Duster 360 </td>
338
+ <td style="text-align:right;"> 14.3 </td>
339
+ <td style="text-align:right;"> 8 </td>
340
+ <td style="text-align:right;"> 360.0 </td>
341
+ <td style="text-align:right;"> 245 </td>
342
+ <td style="text-align:right;"> 3.21 </td>
343
+ <td style="text-align:right;"> 3.570 </td>
344
+ <td style="text-align:right;"> 15.84 </td>
345
+ <td style="text-align:right;"> 0 </td>
346
+ <td style="text-align:right;"> 0 </td>
347
+ <td style="text-align:right;"> 3 </td>
348
+ <td style="text-align:right;"> 4 </td>
349
+ </tr>
350
+ <tr>
351
+ <td style="text-align:left;"> Merc 240D </td>
352
+ <td style="text-align:right;"> 24.4 </td>
353
+ <td style="text-align:right;"> 4 </td>
354
+ <td style="text-align:right;"> 146.7 </td>
355
+ <td style="text-align:right;"> 62 </td>
356
+ <td style="text-align:right;"> 3.69 </td>
357
+ <td style="text-align:right;"> 3.190 </td>
358
+ <td style="text-align:right;"> 20.00 </td>
359
+ <td style="text-align:right;"> 1 </td>
360
+ <td style="text-align:right;"> 0 </td>
361
+ <td style="text-align:right;"> 4 </td>
362
+ <td style="text-align:right;"> 2 </td>
363
+ </tr>
364
+ <tr>
365
+ <td style="text-align:left;"> Merc 230 </td>
366
+ <td style="text-align:right;"> 22.8 </td>
367
+ <td style="text-align:right;"> 4 </td>
368
+ <td style="text-align:right;"> 140.8 </td>
369
+ <td style="text-align:right;"> 95 </td>
370
+ <td style="text-align:right;"> 3.92 </td>
371
+ <td style="text-align:right;"> 3.150 </td>
372
+ <td style="text-align:right;"> 22.90 </td>
373
+ <td style="text-align:right;"> 1 </td>
374
+ <td style="text-align:right;"> 0 </td>
375
+ <td style="text-align:right;"> 4 </td>
376
+ <td style="text-align:right;"> 2 </td>
377
+ </tr>
378
+ <tr>
379
+ <td style="text-align:left;"> Merc 280 </td>
380
+ <td style="text-align:right;"> 19.2 </td>
381
+ <td style="text-align:right;"> 6 </td>
382
+ <td style="text-align:right;"> 167.6 </td>
383
+ <td style="text-align:right;"> 123 </td>
384
+ <td style="text-align:right;"> 3.92 </td>
385
+ <td style="text-align:right;"> 3.440 </td>
386
+ <td style="text-align:right;"> 18.30 </td>
387
+ <td style="text-align:right;"> 1 </td>
388
+ <td style="text-align:right;"> 0 </td>
389
+ <td style="text-align:right;"> 4 </td>
390
+ <td style="text-align:right;"> 4 </td>
391
+ </tr>
392
+ <tr>
393
+ <td style="text-align:left;"> Merc 280C </td>
394
+ <td style="text-align:right;"> 17.8 </td>
395
+ <td style="text-align:right;"> 6 </td>
396
+ <td style="text-align:right;"> 167.6 </td>
397
+ <td style="text-align:right;"> 123 </td>
398
+ <td style="text-align:right;"> 3.92 </td>
399
+ <td style="text-align:right;"> 3.440 </td>
400
+ <td style="text-align:right;"> 18.90 </td>
401
+ <td style="text-align:right;"> 1 </td>
402
+ <td style="text-align:right;"> 0 </td>
403
+ <td style="text-align:right;"> 4 </td>
404
+ <td style="text-align:right;"> 4 </td>
405
+ </tr>
406
+ <tr>
407
+ <td style="text-align:left;"> Merc 450SE </td>
408
+ <td style="text-align:right;"> 16.4 </td>
409
+ <td style="text-align:right;"> 8 </td>
410
+ <td style="text-align:right;"> 275.8 </td>
411
+ <td style="text-align:right;"> 180 </td>
412
+ <td style="text-align:right;"> 3.07 </td>
413
+ <td style="text-align:right;"> 4.070 </td>
414
+ <td style="text-align:right;"> 17.40 </td>
415
+ <td style="text-align:right;"> 0 </td>
416
+ <td style="text-align:right;"> 0 </td>
417
+ <td style="text-align:right;"> 3 </td>
418
+ <td style="text-align:right;"> 3 </td>
419
+ </tr>
420
+ <tr>
421
+ <td style="text-align:left;"> Merc 450SL </td>
422
+ <td style="text-align:right;"> 17.3 </td>
423
+ <td style="text-align:right;"> 8 </td>
424
+ <td style="text-align:right;"> 275.8 </td>
425
+ <td style="text-align:right;"> 180 </td>
426
+ <td style="text-align:right;"> 3.07 </td>
427
+ <td style="text-align:right;"> 3.730 </td>
428
+ <td style="text-align:right;"> 17.60 </td>
429
+ <td style="text-align:right;"> 0 </td>
430
+ <td style="text-align:right;"> 0 </td>
431
+ <td style="text-align:right;"> 3 </td>
432
+ <td style="text-align:right;"> 3 </td>
433
+ </tr>
434
+ <tr>
435
+ <td style="text-align:left;"> Merc 450SLC </td>
436
+ <td style="text-align:right;"> 15.2 </td>
437
+ <td style="text-align:right;"> 8 </td>
438
+ <td style="text-align:right;"> 275.8 </td>
439
+ <td style="text-align:right;"> 180 </td>
440
+ <td style="text-align:right;"> 3.07 </td>
441
+ <td style="text-align:right;"> 3.780 </td>
442
+ <td style="text-align:right;"> 18.00 </td>
443
+ <td style="text-align:right;"> 0 </td>
444
+ <td style="text-align:right;"> 0 </td>
445
+ <td style="text-align:right;"> 3 </td>
446
+ <td style="text-align:right;"> 3 </td>
447
+ </tr>
448
+ <tr>
449
+ <td style="text-align:left;"> Cadillac Fleetwood </td>
450
+ <td style="text-align:right;"> 10.4 </td>
451
+ <td style="text-align:right;"> 8 </td>
452
+ <td style="text-align:right;"> 472.0 </td>
453
+ <td style="text-align:right;"> 205 </td>
454
+ <td style="text-align:right;"> 2.93 </td>
455
+ <td style="text-align:right;"> 5.250 </td>
456
+ <td style="text-align:right;"> 17.98 </td>
457
+ <td style="text-align:right;"> 0 </td>
458
+ <td style="text-align:right;"> 0 </td>
459
+ <td style="text-align:right;"> 3 </td>
460
+ <td style="text-align:right;"> 4 </td>
461
+ </tr>
462
+ <tr>
463
+ <td style="text-align:left;"> Lincoln Continental </td>
464
+ <td style="text-align:right;"> 10.4 </td>
465
+ <td style="text-align:right;"> 8 </td>
466
+ <td style="text-align:right;"> 460.0 </td>
467
+ <td style="text-align:right;"> 215 </td>
468
+ <td style="text-align:right;"> 3.00 </td>
469
+ <td style="text-align:right;"> 5.424 </td>
470
+ <td style="text-align:right;"> 17.82 </td>
471
+ <td style="text-align:right;"> 0 </td>
472
+ <td style="text-align:right;"> 0 </td>
473
+ <td style="text-align:right;"> 3 </td>
474
+ <td style="text-align:right;"> 4 </td>
475
+ </tr>
476
+ <tr>
477
+ <td style="text-align:left;"> Chrysler Imperial </td>
478
+ <td style="text-align:right;"> 14.7 </td>
479
+ <td style="text-align:right;"> 8 </td>
480
+ <td style="text-align:right;"> 440.0 </td>
481
+ <td style="text-align:right;"> 230 </td>
482
+ <td style="text-align:right;"> 3.23 </td>
483
+ <td style="text-align:right;"> 5.345 </td>
484
+ <td style="text-align:right;"> 17.42 </td>
485
+ <td style="text-align:right;"> 0 </td>
486
+ <td style="text-align:right;"> 0 </td>
487
+ <td style="text-align:right;"> 3 </td>
488
+ <td style="text-align:right;"> 4 </td>
489
+ </tr>
490
+ <tr>
491
+ <td style="text-align:left;"> Fiat 128 </td>
492
+ <td style="text-align:right;"> 32.4 </td>
493
+ <td style="text-align:right;"> 4 </td>
494
+ <td style="text-align:right;"> 78.7 </td>
495
+ <td style="text-align:right;"> 66 </td>
496
+ <td style="text-align:right;"> 4.08 </td>
497
+ <td style="text-align:right;"> 2.200 </td>
498
+ <td style="text-align:right;"> 19.47 </td>
499
+ <td style="text-align:right;"> 1 </td>
500
+ <td style="text-align:right;"> 1 </td>
501
+ <td style="text-align:right;"> 4 </td>
502
+ <td style="text-align:right;"> 1 </td>
503
+ </tr>
504
+ <tr>
505
+ <td style="text-align:left;"> Honda Civic </td>
506
+ <td style="text-align:right;"> 30.4 </td>
507
+ <td style="text-align:right;"> 4 </td>
508
+ <td style="text-align:right;"> 75.7 </td>
509
+ <td style="text-align:right;"> 52 </td>
510
+ <td style="text-align:right;"> 4.93 </td>
511
+ <td style="text-align:right;"> 1.615 </td>
512
+ <td style="text-align:right;"> 18.52 </td>
513
+ <td style="text-align:right;"> 1 </td>
514
+ <td style="text-align:right;"> 1 </td>
515
+ <td style="text-align:right;"> 4 </td>
516
+ <td style="text-align:right;"> 2 </td>
517
+ </tr>
518
+ <tr>
519
+ <td style="text-align:left;"> Toyota Corolla </td>
520
+ <td style="text-align:right;"> 33.9 </td>
521
+ <td style="text-align:right;"> 4 </td>
522
+ <td style="text-align:right;"> 71.1 </td>
523
+ <td style="text-align:right;"> 65 </td>
524
+ <td style="text-align:right;"> 4.22 </td>
525
+ <td style="text-align:right;"> 1.835 </td>
526
+ <td style="text-align:right;"> 19.90 </td>
527
+ <td style="text-align:right;"> 1 </td>
528
+ <td style="text-align:right;"> 1 </td>
529
+ <td style="text-align:right;"> 4 </td>
530
+ <td style="text-align:right;"> 1 </td>
531
+ </tr>
532
+ <tr>
533
+ <td style="text-align:left;"> Toyota Corona </td>
534
+ <td style="text-align:right;"> 21.5 </td>
535
+ <td style="text-align:right;"> 4 </td>
536
+ <td style="text-align:right;"> 120.1 </td>
537
+ <td style="text-align:right;"> 97 </td>
538
+ <td style="text-align:right;"> 3.70 </td>
539
+ <td style="text-align:right;"> 2.465 </td>
540
+ <td style="text-align:right;"> 20.01 </td>
541
+ <td style="text-align:right;"> 1 </td>
542
+ <td style="text-align:right;"> 0 </td>
543
+ <td style="text-align:right;"> 3 </td>
544
+ <td style="text-align:right;"> 1 </td>
545
+ </tr>
546
+ <tr>
547
+ <td style="text-align:left;"> Dodge Challenger </td>
548
+ <td style="text-align:right;"> 15.5 </td>
549
+ <td style="text-align:right;"> 8 </td>
550
+ <td style="text-align:right;"> 318.0 </td>
551
+ <td style="text-align:right;"> 150 </td>
552
+ <td style="text-align:right;"> 2.76 </td>
553
+ <td style="text-align:right;"> 3.520 </td>
554
+ <td style="text-align:right;"> 16.87 </td>
555
+ <td style="text-align:right;"> 0 </td>
556
+ <td style="text-align:right;"> 0 </td>
557
+ <td style="text-align:right;"> 3 </td>
558
+ <td style="text-align:right;"> 2 </td>
559
+ </tr>
560
+ <tr>
561
+ <td style="text-align:left;"> AMC Javelin </td>
562
+ <td style="text-align:right;"> 15.2 </td>
563
+ <td style="text-align:right;"> 8 </td>
564
+ <td style="text-align:right;"> 304.0 </td>
565
+ <td style="text-align:right;"> 150 </td>
566
+ <td style="text-align:right;"> 3.15 </td>
567
+ <td style="text-align:right;"> 3.435 </td>
568
+ <td style="text-align:right;"> 17.30 </td>
569
+ <td style="text-align:right;"> 0 </td>
570
+ <td style="text-align:right;"> 0 </td>
571
+ <td style="text-align:right;"> 3 </td>
572
+ <td style="text-align:right;"> 2 </td>
573
+ </tr>
574
+ <tr>
575
+ <td style="text-align:left;"> Camaro Z28 </td>
576
+ <td style="text-align:right;"> 13.3 </td>
577
+ <td style="text-align:right;"> 8 </td>
578
+ <td style="text-align:right;"> 350.0 </td>
579
+ <td style="text-align:right;"> 245 </td>
580
+ <td style="text-align:right;"> 3.73 </td>
581
+ <td style="text-align:right;"> 3.840 </td>
582
+ <td style="text-align:right;"> 15.41 </td>
583
+ <td style="text-align:right;"> 0 </td>
584
+ <td style="text-align:right;"> 0 </td>
585
+ <td style="text-align:right;"> 3 </td>
586
+ <td style="text-align:right;"> 4 </td>
587
+ </tr>
588
+ <tr>
589
+ <td style="text-align:left;"> Pontiac Firebird </td>
590
+ <td style="text-align:right;"> 19.2 </td>
591
+ <td style="text-align:right;"> 8 </td>
592
+ <td style="text-align:right;"> 400.0 </td>
593
+ <td style="text-align:right;"> 175 </td>
594
+ <td style="text-align:right;"> 3.08 </td>
595
+ <td style="text-align:right;"> 3.845 </td>
596
+ <td style="text-align:right;"> 17.05 </td>
597
+ <td style="text-align:right;"> 0 </td>
598
+ <td style="text-align:right;"> 0 </td>
599
+ <td style="text-align:right;"> 3 </td>
600
+ <td style="text-align:right;"> 2 </td>
601
+ </tr>
602
+ <tr>
603
+ <td style="text-align:left;"> Fiat X1-9 </td>
604
+ <td style="text-align:right;"> 27.3 </td>
605
+ <td style="text-align:right;"> 4 </td>
606
+ <td style="text-align:right;"> 79.0 </td>
607
+ <td style="text-align:right;"> 66 </td>
608
+ <td style="text-align:right;"> 4.08 </td>
609
+ <td style="text-align:right;"> 1.935 </td>
610
+ <td style="text-align:right;"> 18.90 </td>
611
+ <td style="text-align:right;"> 1 </td>
612
+ <td style="text-align:right;"> 1 </td>
613
+ <td style="text-align:right;"> 4 </td>
614
+ <td style="text-align:right;"> 1 </td>
615
+ </tr>
616
+ <tr>
617
+ <td style="text-align:left;"> Porsche 914-2 </td>
618
+ <td style="text-align:right;"> 26.0 </td>
619
+ <td style="text-align:right;"> 4 </td>
620
+ <td style="text-align:right;"> 120.3 </td>
621
+ <td style="text-align:right;"> 91 </td>
622
+ <td style="text-align:right;"> 4.43 </td>
623
+ <td style="text-align:right;"> 2.140 </td>
624
+ <td style="text-align:right;"> 16.70 </td>
625
+ <td style="text-align:right;"> 0 </td>
626
+ <td style="text-align:right;"> 1 </td>
627
+ <td style="text-align:right;"> 5 </td>
628
+ <td style="text-align:right;"> 2 </td>
629
+ </tr>
630
+ <tr>
631
+ <td style="text-align:left;"> Lotus Europa </td>
632
+ <td style="text-align:right;"> 30.4 </td>
633
+ <td style="text-align:right;"> 4 </td>
634
+ <td style="text-align:right;"> 95.1 </td>
635
+ <td style="text-align:right;"> 113 </td>
636
+ <td style="text-align:right;"> 3.77 </td>
637
+ <td style="text-align:right;"> 1.513 </td>
638
+ <td style="text-align:right;"> 16.90 </td>
639
+ <td style="text-align:right;"> 1 </td>
640
+ <td style="text-align:right;"> 1 </td>
641
+ <td style="text-align:right;"> 5 </td>
642
+ <td style="text-align:right;"> 2 </td>
643
+ </tr>
644
+ <tr>
645
+ <td style="text-align:left;"> Ford Pantera L </td>
646
+ <td style="text-align:right;"> 15.8 </td>
647
+ <td style="text-align:right;"> 8 </td>
648
+ <td style="text-align:right;"> 351.0 </td>
649
+ <td style="text-align:right;"> 264 </td>
650
+ <td style="text-align:right;"> 4.22 </td>
651
+ <td style="text-align:right;"> 3.170 </td>
652
+ <td style="text-align:right;"> 14.50 </td>
653
+ <td style="text-align:right;"> 0 </td>
654
+ <td style="text-align:right;"> 1 </td>
655
+ <td style="text-align:right;"> 5 </td>
656
+ <td style="text-align:right;"> 4 </td>
657
+ </tr>
658
+ <tr>
659
+ <td style="text-align:left;"> Ferrari Dino </td>
660
+ <td style="text-align:right;"> 19.7 </td>
661
+ <td style="text-align:right;"> 6 </td>
662
+ <td style="text-align:right;"> 145.0 </td>
663
+ <td style="text-align:right;"> 175 </td>
664
+ <td style="text-align:right;"> 3.62 </td>
665
+ <td style="text-align:right;"> 2.770 </td>
666
+ <td style="text-align:right;"> 15.50 </td>
667
+ <td style="text-align:right;"> 0 </td>
668
+ <td style="text-align:right;"> 1 </td>
669
+ <td style="text-align:right;"> 5 </td>
670
+ <td style="text-align:right;"> 6 </td>
671
+ </tr>
672
+ <tr>
673
+ <td style="text-align:left;"> Maserati Bora </td>
674
+ <td style="text-align:right;"> 15.0 </td>
675
+ <td style="text-align:right;"> 8 </td>
676
+ <td style="text-align:right;"> 301.0 </td>
677
+ <td style="text-align:right;"> 335 </td>
678
+ <td style="text-align:right;"> 3.54 </td>
679
+ <td style="text-align:right;"> 3.570 </td>
680
+ <td style="text-align:right;"> 14.60 </td>
681
+ <td style="text-align:right;"> 0 </td>
682
+ <td style="text-align:right;"> 1 </td>
683
+ <td style="text-align:right;"> 5 </td>
684
+ <td style="text-align:right;"> 8 </td>
685
+ </tr>
686
+ <tr>
687
+ <td style="text-align:left;"> Volvo 142E </td>
688
+ <td style="text-align:right;"> 21.4 </td>
689
+ <td style="text-align:right;"> 4 </td>
690
+ <td style="text-align:right;"> 121.0 </td>
691
+ <td style="text-align:right;"> 109 </td>
692
+ <td style="text-align:right;"> 4.11 </td>
693
+ <td style="text-align:right;"> 2.780 </td>
694
+ <td style="text-align:right;"> 18.60 </td>
695
+ <td style="text-align:right;"> 1 </td>
696
+ <td style="text-align:right;"> 1 </td>
697
+ <td style="text-align:right;"> 4 </td>
698
+ <td style="text-align:right;"> 2 </td>
699
+ </tr>
700
+ </tbody>
701
+ </table>
702
+
703
+
704
+ ## Graphics with ggplot
705
+
706
+
707
+ ```ruby
308
708
  require 'ggplot'
309
709
 
310
- sp = ScatterPlot.new(~:midwest, x: :area, y: :poptotal)
311
- sp.title = "Midwest Dataset - Scatterplot"
312
- sp.subtitle = "Area Vs Population"
313
- sp.caption = "Source: midwest"
314
- sp.x_label = "Area"
315
- sp.y_label = "Population"
316
- sp.group_by(color: :state, size: :popdensity) # try sp.group_by(color: :state)
317
- # available methods: "lm", "glm", "loess", "gam"
318
- sp.add_smoothing_line(method: "glm")
319
- sp.plot('svg')
320
-
321
- # require input from the user so that the script does not end removing the plot from
322
- # the screen
710
+ R.theme_set R.theme_bw
711
+
712
+ # Data Prep
713
+ mtcars = ~:mtcars
714
+ mtcars.car_name = R.rownames(:mtcars)
715
+ # compute normalized mpg
716
+ mtcars.mpg_z = ((mtcars.mpg - mtcars.mpg.mean)/mtcars.mpg.sd).round 2
717
+ mtcars.mpg_type = mtcars.mpg_z < 0 ? "below" : "above"
718
+ mtcars = mtcars[mtcars.mpg_z.order, :all]
719
+ # convert to factor to retain sorted order in plot
720
+ mtcars.car_name = mtcars.car_name.factor levels: mtcars.car_name
721
+
722
+ # Diverging Barcharts
723
+ gg = mtcars.ggplot(E.aes(x: :car_name, y: :mpg_z, label: :mpg_z)) +
724
+ R.geom_bar(E.aes(fill: :mpg_type), stat: 'identity', width: 0.5) +
725
+ R.scale_fill_manual(name: "Mileage",
726
+ labels: R.c("Above Average", "Below Average"),
727
+ values: R.c("above": "#00ba38", "below": "#f8766d")) +
728
+ R.labs(subtitle: "Normalised mileage from 'mtcars'",
729
+ title: "Diverging Bars") +
730
+ R.coord_flip()
731
+
732
+ puts gg
323
733
  ```
324
734
 
325
- ![Midwest Plot with 'glm' function and modified theme](https://user-images.githubusercontent.com/3999729/47120345-a903ae80-d244-11e8-9be3-a0db13cf51ab.PNG)
735
+
736
+ ![](/home/rbotafogo/desenv/galaaz/blogs/manual/manual_files/figure-html/diverging_bar.png)<!-- -->
737
+
738
+
739
+ [TO BE CONTINUED...]
740
+
741
+
742
+ # Contributing
743
+
744
+
745
+ * Fork it
746
+ * Create your feature branch (git checkout -b my-new-feature)
747
+ * Write Tests!
748
+ * Commit your changes (git commit -am 'Add some feature')
749
+ * Push to the branch (git push origin my-new-feature)
750
+ * Create new Pull Request
751
+