galaaz 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +319 -32
- data/Rakefile +16 -2
- data/bin/grun +1 -1
- data/bin/gstudio +1 -1
- data/blogs/gknit/gknit.Rmd +191 -104
- data/blogs/gknit/gknit.html +129 -57
- data/blogs/gknit/gknit.md +230 -104
- data/blogs/gknit/gknit.pdf +0 -0
- data/blogs/gknit/gknit.tex +1360 -0
- data/blogs/gknit/lst.rds +0 -0
- data/blogs/gknit/marshal.dump +0 -0
- data/blogs/gknit/stats.bib +27 -0
- data/blogs/manual/manual.Rmd +114 -2
- data/blogs/manual/manual.html +251 -8
- data/blogs/manual/manual.md +319 -8
- data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
- data/blogs/ruby_plot/ruby_plot.html +3 -3
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
- data/examples/misc/moneyball.rb +1 -1
- data/examples/misc/subsetting.rb +37 -37
- data/lib/R_interface/robject.rb +2 -12
- data/lib/R_interface/ruby_extensions.rb +5 -2
- data/lib/gknit/knitr_engine.rb +2 -9
- data/lib/util/inline_file.rb +7 -3
- data/specs/tmp.rb +15 -24
- data/version.rb +1 -1
- metadata +7 -4
- data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
- data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f328b999e2b5b132053b133a1f1fcc3ddd6f5a295cc040629a6989150a765775
|
4
|
+
data.tar.gz: f6bce01abc3f189f1e16f8cf2691a7bd14d2962f295dccda5a00e564e4470cc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b287e9d5883723a8e378d88c5df28d7097ca3ca14b6648641415c2734d4204473f71ad173d45b0946e5e02e67d9c1da168a06aeaf2472c388232c7acf44cdc5
|
7
|
+
data.tar.gz: 57a0c432b785e89ee1df8c38f2710736e2150b2024e11b1ed1e0437e1903a96934b6be135fe1ffe54d9fb891527d15275f1c119cdf6f1a453d47c991b268d273
|
data/README.md
CHANGED
@@ -1,27 +1,3 @@
|
|
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
|
-
---
|
22
|
-
|
23
|
-
|
24
|
-
|
25
1
|
# Introduction
|
26
2
|
|
27
3
|
Galaaz is a system for tightly coupling Ruby and R. Ruby is a powerful language, with a large
|
@@ -221,22 +197,22 @@ vec = R.c(1, hello, 5)
|
|
221
197
|
## (eval):1:in `exec_ruby'
|
222
198
|
## /home/rbotafogo/desenv/galaaz/lib/util/exec_ruby.rb:141:in `instance_eval'
|
223
199
|
## /home/rbotafogo/desenv/galaaz/lib/util/exec_ruby.rb:141:in `exec_ruby'
|
224
|
-
## /home/rbotafogo/desenv/galaaz/lib/gknit/knitr_engine.rb:
|
200
|
+
## /home/rbotafogo/desenv/galaaz/lib/gknit/knitr_engine.rb:650:in `block in initialize'
|
225
201
|
## /home/rbotafogo/desenv/galaaz/lib/R_interface/ruby_callback.rb:77:in `call'
|
226
202
|
## /home/rbotafogo/desenv/galaaz/lib/R_interface/ruby_callback.rb:77:in `callback'
|
227
203
|
## (eval):3:in `function(...) {\n rb_method(...)'
|
228
204
|
## unknown.r:1:in `in_dir'
|
229
205
|
## unknown.r:1:in `block_exec:BLOCK0'
|
230
|
-
## /home/rbotafogo/lib/graalvm-ce-1.0.0-
|
231
|
-
## /home/rbotafogo/lib/graalvm-ce-1.0.0-
|
232
|
-
## /home/rbotafogo/lib/graalvm-ce-1.0.0-
|
233
|
-
## /home/rbotafogo/lib/graalvm-ce-1.0.0-
|
206
|
+
## /home/rbotafogo/lib/graalvm-ce-1.0.0-rc16/jre/languages/R/library/knitr/R/block.R:102:in `block_exec'
|
207
|
+
## /home/rbotafogo/lib/graalvm-ce-1.0.0-rc16/jre/languages/R/library/knitr/R/block.R:92:in `call_block'
|
208
|
+
## /home/rbotafogo/lib/graalvm-ce-1.0.0-rc16/jre/languages/R/library/knitr/R/block.R:6:in `process_group.block'
|
209
|
+
## /home/rbotafogo/lib/graalvm-ce-1.0.0-rc16/jre/languages/R/library/knitr/R/block.R:3:in `<no source>'
|
234
210
|
## unknown.r:1:in `withCallingHandlers'
|
235
211
|
## unknown.r:1:in `process_file'
|
236
212
|
## unknown.r:1:in `<no source>:BLOCK1'
|
237
|
-
## /home/rbotafogo/lib/graalvm-ce-1.0.0-
|
213
|
+
## /home/rbotafogo/lib/graalvm-ce-1.0.0-rc16/jre/languages/R/library/knitr/R/output.R:129:in `<no source>'
|
238
214
|
## unknown.r:1:in `<no source>:BLOCK1'
|
239
|
-
## /home/rbotafogo/lib/graalvm-ce-1.0.0-
|
215
|
+
## /home/rbotafogo/lib/graalvm-ce-1.0.0-rc16/jre/languages/R/library/rmarkdown/R/render.R:162:in `<no source>'
|
240
216
|
## <REPL>:5:in `<repl wrapper>'
|
241
217
|
## <REPL>:1
|
242
218
|
```
|
@@ -1764,6 +1740,288 @@ puts @flights_sm.head.as__data__frame
|
|
1764
1740
|
## 6 2013 1 1 -4 12 719 150 -16 287.6000
|
1765
1741
|
```
|
1766
1742
|
|
1743
|
+
## Summarising data
|
1744
|
+
|
1745
|
+
Function 'summarise' calculates summaries for the data frame. When no 'group_by' is used
|
1746
|
+
a single value is obtained from the data frame:
|
1747
|
+
|
1748
|
+
|
1749
|
+
```ruby
|
1750
|
+
puts @flights.summarise(delay: E.mean(:dep_delay, na__rm: true)).as__data__frame
|
1751
|
+
```
|
1752
|
+
|
1753
|
+
```
|
1754
|
+
## delay
|
1755
|
+
## 1 12.63907
|
1756
|
+
```
|
1757
|
+
|
1758
|
+
When a data frame is groupe with 'group_by' summaries apply to the given group:
|
1759
|
+
|
1760
|
+
|
1761
|
+
```ruby
|
1762
|
+
by_day = @flights.group_by(:year, :month, :day)
|
1763
|
+
puts by_day.summarise(delay: :dep_delay.mean(na__rm: true)).head.as__data__frame
|
1764
|
+
```
|
1765
|
+
|
1766
|
+
```
|
1767
|
+
## year month day delay
|
1768
|
+
## 1 2013 1 1 11.548926
|
1769
|
+
## 2 2013 1 2 13.858824
|
1770
|
+
## 3 2013 1 3 10.987832
|
1771
|
+
## 4 2013 1 4 8.951595
|
1772
|
+
## 5 2013 1 5 5.732218
|
1773
|
+
## 6 2013 1 6 7.148014
|
1774
|
+
```
|
1775
|
+
|
1776
|
+
Next we put many operations together by pipping them one after the other:
|
1777
|
+
|
1778
|
+
|
1779
|
+
```ruby
|
1780
|
+
delays = @flights.
|
1781
|
+
group_by(:dest).
|
1782
|
+
summarise(
|
1783
|
+
count: E.n,
|
1784
|
+
dist: :distance.mean(na__rm: true),
|
1785
|
+
delay: :arr_delay.mean(na__rm: true)).
|
1786
|
+
filter(:count > 20, :dest != "NHL")
|
1787
|
+
|
1788
|
+
puts delays.as__data__frame
|
1789
|
+
```
|
1790
|
+
|
1791
|
+
```
|
1792
|
+
## dest count dist delay
|
1793
|
+
## 1 ABQ 254 1826.00000 4.38188976
|
1794
|
+
## 2 ACK 265 199.00000 4.85227273
|
1795
|
+
## 3 ALB 439 143.00000 14.39712919
|
1796
|
+
## 4 ATL 17215 757.10822 11.30011285
|
1797
|
+
## 5 AUS 2439 1514.25297 6.01990875
|
1798
|
+
## 6 AVL 275 583.58182 8.00383142
|
1799
|
+
## 7 BDL 443 116.00000 7.04854369
|
1800
|
+
## 8 BGR 375 378.00000 8.02793296
|
1801
|
+
## 9 BHM 297 865.99663 16.87732342
|
1802
|
+
## 10 BNA 6333 758.21348 11.81245891
|
1803
|
+
## 11 BOS 15508 190.63696 2.91439222
|
1804
|
+
## 12 BQN 896 1578.98326 8.24549550
|
1805
|
+
## 13 BTV 2589 265.09154 8.95099602
|
1806
|
+
## 14 BUF 4681 296.80837 8.94595186
|
1807
|
+
## 15 BUR 371 2465.00000 8.17567568
|
1808
|
+
## 16 BWI 1781 179.41830 10.72673385
|
1809
|
+
## 17 BZN 36 1882.00000 7.60000000
|
1810
|
+
## 18 CAE 116 603.55172 41.76415094
|
1811
|
+
## 19 CAK 864 397.00000 19.69833729
|
1812
|
+
## 20 CHO 52 305.00000 9.50000000
|
1813
|
+
## 21 CHS 2884 632.91678 10.59296847
|
1814
|
+
## 22 CLE 4573 414.17428 9.18161129
|
1815
|
+
## 23 CLT 14064 538.02730 7.36031885
|
1816
|
+
## 24 CMH 3524 476.55505 10.60132291
|
1817
|
+
## 25 CRW 138 444.00000 14.67164179
|
1818
|
+
## 26 CVG 3941 575.15986 15.36456376
|
1819
|
+
## 27 DAY 1525 537.10230 12.68048606
|
1820
|
+
## 28 DCA 9705 211.00618 9.06695204
|
1821
|
+
## 29 DEN 7266 1614.67836 8.60650021
|
1822
|
+
## 30 DFW 8738 1383.04303 0.32212685
|
1823
|
+
## 31 DSM 569 1020.88752 19.00573614
|
1824
|
+
## 32 DTW 9384 498.12852 5.42996346
|
1825
|
+
## 33 EGE 213 1735.70892 6.30434783
|
1826
|
+
## 34 FLL 12055 1070.06877 8.08212154
|
1827
|
+
## 35 GRR 765 605.78170 18.18956044
|
1828
|
+
## 36 GSO 1606 449.84184 14.11260054
|
1829
|
+
## 37 GSP 849 595.95995 15.93544304
|
1830
|
+
## 38 HNL 707 4972.67468 -1.36519258
|
1831
|
+
## 39 HOU 2115 1420.15508 7.17618819
|
1832
|
+
## 40 IAD 5700 224.84684 13.86420212
|
1833
|
+
## 41 IAH 7198 1407.20672 4.24079040
|
1834
|
+
## 42 ILM 110 500.00000 4.63551402
|
1835
|
+
## 43 IND 2077 652.26288 9.94043412
|
1836
|
+
## 44 JAC 25 1875.60000 28.09523810
|
1837
|
+
## 45 JAX 2720 824.67610 11.84483416
|
1838
|
+
## 46 LAS 5997 2240.96148 0.25772849
|
1839
|
+
## 47 LAX 16174 2468.62236 0.54711094
|
1840
|
+
## 48 LGB 668 2465.00000 -0.06202723
|
1841
|
+
## 49 MCI 2008 1097.69522 14.51405836
|
1842
|
+
## 50 MCO 14082 943.11057 5.45464309
|
1843
|
+
## 51 MDW 4113 718.04595 12.36422360
|
1844
|
+
## 52 MEM 1789 954.20123 10.64531435
|
1845
|
+
## 53 MHT 1009 207.02973 14.78755365
|
1846
|
+
## 54 MIA 11728 1091.55244 0.29905978
|
1847
|
+
## 55 MKE 2802 733.38151 14.16722038
|
1848
|
+
## 56 MSN 572 803.95455 20.19604317
|
1849
|
+
## 57 MSP 7185 1017.40167 7.27016886
|
1850
|
+
## 58 MSY 3799 1177.70571 6.49017497
|
1851
|
+
## 59 MVY 221 173.00000 -0.28571429
|
1852
|
+
## 60 MYR 59 550.66102 4.60344828
|
1853
|
+
## 61 OAK 312 2576.00000 3.07766990
|
1854
|
+
## 62 OKC 346 1325.00000 30.61904762
|
1855
|
+
## 63 OMA 849 1135.56655 14.69889841
|
1856
|
+
## 64 ORD 17283 729.00081 5.87661475
|
1857
|
+
## 65 ORF 1536 288.52344 10.94909344
|
1858
|
+
## 66 PBI 6554 1028.83811 8.56297210
|
1859
|
+
## 67 PDX 1354 2445.56573 5.14157973
|
1860
|
+
## 68 PHL 1632 94.32353 10.12719014
|
1861
|
+
## 69 PHX 4656 2141.30326 2.09704733
|
1862
|
+
## 70 PIT 2875 334.06122 7.68099053
|
1863
|
+
## 71 PSE 365 1617.00000 7.87150838
|
1864
|
+
## 72 PVD 376 160.00000 16.23463687
|
1865
|
+
## 73 PWM 2352 276.12840 11.66040210
|
1866
|
+
## 74 RDU 8163 426.75769 10.05238095
|
1867
|
+
## 75 RIC 2454 281.40465 20.11125320
|
1868
|
+
## 76 ROC 2416 259.25083 11.56064461
|
1869
|
+
## 77 RSW 3537 1072.85327 3.23814963
|
1870
|
+
## 78 SAN 2737 2437.29923 3.13916574
|
1871
|
+
## 79 SAT 686 1578.34111 6.94537178
|
1872
|
+
## 80 SAV 804 709.18408 15.12950601
|
1873
|
+
## 81 SDF 1157 645.98358 12.66938406
|
1874
|
+
## 82 SEA 3923 2412.66531 -1.09909910
|
1875
|
+
## 83 SFO 13331 2577.92356 2.67289152
|
1876
|
+
## 84 SJC 329 2569.00000 3.44817073
|
1877
|
+
## 85 SJU 5819 1599.83365 2.52052659
|
1878
|
+
## 86 SLC 2467 1986.98662 0.17625459
|
1879
|
+
## 87 SMF 284 2521.00000 12.10992908
|
1880
|
+
## 88 SNA 825 2434.00000 -7.86822660
|
1881
|
+
## 89 SRQ 1211 1044.65153 3.08243131
|
1882
|
+
## 90 STL 4339 878.72321 11.07846451
|
1883
|
+
## 91 STT 522 1626.98276 -3.83590734
|
1884
|
+
## 92 SYR 1761 205.92164 8.90392501
|
1885
|
+
## 93 TPA 7466 1003.93557 7.40852503
|
1886
|
+
## 94 TUL 315 1215.00000 33.65986395
|
1887
|
+
## 95 TVC 101 652.38614 12.96842105
|
1888
|
+
## 96 TYS 631 638.80983 24.06920415
|
1889
|
+
## 97 XNA 1036 1142.50579 7.46572581
|
1890
|
+
```
|
1891
|
+
|
1892
|
+
# Using Data Table
|
1893
|
+
|
1894
|
+
|
1895
|
+
```ruby
|
1896
|
+
R.library('data.table')
|
1897
|
+
R.install_and_loads('curl')
|
1898
|
+
|
1899
|
+
input = "https://raw.githubusercontent.com/Rdatatable/data.table/master/vignettes/flights14.csv"
|
1900
|
+
@flights = R.fread(input)
|
1901
|
+
puts @flights
|
1902
|
+
puts @flights.dim
|
1903
|
+
```
|
1904
|
+
|
1905
|
+
```
|
1906
|
+
## year month day dep_delay arr_delay carrier origin dest air_time
|
1907
|
+
## 1: 2014 1 1 14 13 AA JFK LAX 359
|
1908
|
+
## 2: 2014 1 1 -3 13 AA JFK LAX 363
|
1909
|
+
## 3: 2014 1 1 2 9 AA JFK LAX 351
|
1910
|
+
## 4: 2014 1 1 -8 -26 AA LGA PBI 157
|
1911
|
+
## 5: 2014 1 1 2 1 AA JFK LAX 350
|
1912
|
+
## ---
|
1913
|
+
## 253312: 2014 10 31 1 -30 UA LGA IAH 201
|
1914
|
+
## 253313: 2014 10 31 -5 -14 UA EWR IAH 189
|
1915
|
+
## 253314: 2014 10 31 -8 16 MQ LGA RDU 83
|
1916
|
+
## 253315: 2014 10 31 -4 15 MQ LGA DTW 75
|
1917
|
+
## 253316: 2014 10 31 -5 1 MQ LGA SDF 110
|
1918
|
+
## distance hour
|
1919
|
+
## 1: 2475 9
|
1920
|
+
## 2: 2475 11
|
1921
|
+
## 3: 2475 19
|
1922
|
+
## 4: 1035 7
|
1923
|
+
## 5: 2475 13
|
1924
|
+
## ---
|
1925
|
+
## 253312: 1416 14
|
1926
|
+
## 253313: 1400 8
|
1927
|
+
## 253314: 431 11
|
1928
|
+
## 253315: 502 11
|
1929
|
+
## 253316: 659 8
|
1930
|
+
## [1] 253316 11
|
1931
|
+
```
|
1932
|
+
|
1933
|
+
|
1934
|
+
```ruby
|
1935
|
+
|
1936
|
+
data_table = R.data__table(
|
1937
|
+
ID: R.c("b","b","b","a","a","c"),
|
1938
|
+
a: (1..6),
|
1939
|
+
b: (7..12),
|
1940
|
+
c: (13..18)
|
1941
|
+
)
|
1942
|
+
|
1943
|
+
puts data_table
|
1944
|
+
puts data_table.ID
|
1945
|
+
```
|
1946
|
+
|
1947
|
+
```
|
1948
|
+
## ID a b c
|
1949
|
+
## 1: b 1 7 13
|
1950
|
+
## 2: b 2 8 14
|
1951
|
+
## 3: b 3 9 15
|
1952
|
+
## 4: a 4 10 16
|
1953
|
+
## 5: a 5 11 17
|
1954
|
+
## 6: c 6 12 18
|
1955
|
+
## [1] "b" "b" "b" "a" "a" "c"
|
1956
|
+
```
|
1957
|
+
|
1958
|
+
|
1959
|
+
```ruby
|
1960
|
+
# subset rows in i
|
1961
|
+
ans = @flights[(:origin.eq "JFK") & (:month.eq 6)]
|
1962
|
+
puts ans.head
|
1963
|
+
|
1964
|
+
# Get the first two rows from flights.
|
1965
|
+
|
1966
|
+
ans = @flights[(1..2)]
|
1967
|
+
puts ans
|
1968
|
+
|
1969
|
+
# Sort flights first by column origin in ascending order, and then by dest in descending order:
|
1970
|
+
|
1971
|
+
# ans = @flights[E.order(:origin, -(:dest))]
|
1972
|
+
# puts ans.head
|
1973
|
+
```
|
1974
|
+
|
1975
|
+
```
|
1976
|
+
## year month day dep_delay arr_delay carrier origin dest air_time
|
1977
|
+
## 1: 2014 6 1 -9 -5 AA JFK LAX 324
|
1978
|
+
## 2: 2014 6 1 -10 -13 AA JFK LAX 329
|
1979
|
+
## 3: 2014 6 1 18 -1 AA JFK LAX 326
|
1980
|
+
## 4: 2014 6 1 -6 -16 AA JFK LAX 320
|
1981
|
+
## 5: 2014 6 1 -4 -45 AA JFK LAX 326
|
1982
|
+
## 6: 2014 6 1 -6 -23 AA JFK LAX 329
|
1983
|
+
## distance hour
|
1984
|
+
## 1: 2475 8
|
1985
|
+
## 2: 2475 12
|
1986
|
+
## 3: 2475 7
|
1987
|
+
## 4: 2475 10
|
1988
|
+
## 5: 2475 18
|
1989
|
+
## 6: 2475 14
|
1990
|
+
## year month day dep_delay arr_delay carrier origin dest air_time
|
1991
|
+
## 1: 2014 1 1 14 13 AA JFK LAX 359
|
1992
|
+
## 2: 2014 1 1 -3 13 AA JFK LAX 363
|
1993
|
+
## distance hour
|
1994
|
+
## 1: 2475 9
|
1995
|
+
## 2: 2475 11
|
1996
|
+
```
|
1997
|
+
|
1998
|
+
|
1999
|
+
```ruby
|
2000
|
+
# Select column(s) in j
|
2001
|
+
# select arr_delay column, but return it as a vector.
|
2002
|
+
|
2003
|
+
ans = @flights[:all, :arr_delay]
|
2004
|
+
puts ans.head
|
2005
|
+
|
2006
|
+
# Select arr_delay column, but return as a data.table instead.
|
2007
|
+
|
2008
|
+
ans = @flights[:all, :arr_delay.list]
|
2009
|
+
puts ans.head
|
2010
|
+
|
2011
|
+
ans = @flights[:all, E.list(:arr_delay, :dep_delay)]
|
2012
|
+
```
|
2013
|
+
|
2014
|
+
```
|
2015
|
+
## [1] 13 13 9 -26 1 0
|
2016
|
+
## arr_delay
|
2017
|
+
## 1: 13
|
2018
|
+
## 2: 13
|
2019
|
+
## 3: 9
|
2020
|
+
## 4: -26
|
2021
|
+
## 5: 1
|
2022
|
+
## 6: 0
|
2023
|
+
```
|
2024
|
+
|
1767
2025
|
# Graphics in Galaaz
|
1768
2026
|
|
1769
2027
|
Creating graphics in Galaaz is quite easy, as it can use all the power of ggplot2. There are
|
@@ -1872,8 +2130,37 @@ puts @mtcars
|
|
1872
2130
|
## Toyota Corolla Toyota Corolla 2.29 above
|
1873
2131
|
```
|
1874
2132
|
Now, lets plot the diverging bar plot. When using gKnit, there is no need to call
|
1875
|
-
'R.awt' to create a plotting device, since gKnit does take care of it
|
2133
|
+
'R.awt' to create a plotting device, since gKnit does take care of it. Galaaz
|
2134
|
+
provides integration with ggplot. The interested reader should check online for more
|
2135
|
+
information on ggplot, since it is outside the scope of this manual describing
|
2136
|
+
how ggplot works. We give here but a brief description on how this plot is generated.
|
2137
|
+
|
2138
|
+
ggplot implements the 'grammar of graphics'. In this approach, plots are build by
|
2139
|
+
adding layers to the plot. On the first layer we describe what we want on the 'x'
|
2140
|
+
and 'y' axis of the plot. In this case, we have 'car_name' on the 'x' axis and
|
2141
|
+
'mpg\_z' on the 'y' axis. Then the type of graph is specified by adding
|
2142
|
+
'geom\_bar' (for a bar graph). We specify that our bars should be filled using
|
2143
|
+
'mpg\_type', which is either 'above' or 'bellow' giving then two colours for
|
2144
|
+
filling. On the next layer we specify the labels for the graph, then we add the
|
2145
|
+
title and subtitle. Finally, in a bar chart usually bars go on the vertical direction,
|
2146
|
+
but in this graph we want the bars to be horizontally layed so we add 'coord\_flip'.
|
2147
|
+
|
2148
|
+
|
2149
|
+
```ruby
|
2150
|
+
require 'ggplot'
|
2151
|
+
|
2152
|
+
puts @mtcars.ggplot(E.aes(x: :car_name, y: :mpg_z, label: :mpg_z)) +
|
2153
|
+
R.geom_bar(E.aes(fill: :mpg_type), stat: 'identity', width: 0.5) +
|
2154
|
+
R.scale_fill_manual(name: 'Mileage',
|
2155
|
+
labels: R.c('Above Average', 'Below Average'),
|
2156
|
+
values: R.c('above': '#00ba38', 'below': '#f8766d')) +
|
2157
|
+
R.labs(subtitle: "Normalised mileage from 'mtcars'",
|
2158
|
+
title: "Diverging Bars") +
|
2159
|
+
R.coord_flip
|
2160
|
+
```
|
2161
|
+
|
1876
2162
|
|
2163
|
+
![](/home/rbotafogo/desenv/galaaz/blogs/manual/manual_files/figure-html/diverging_bar.png)<!-- -->
|
1877
2164
|
|
1878
2165
|
|
1879
2166
|
[TO BE CONTINUED...]
|
data/Rakefile
CHANGED
@@ -35,7 +35,7 @@ class MakeTask < Rake::TaskLib
|
|
35
35
|
# Create class variables for the polyglot options and libs
|
36
36
|
# not yet possible to run native with R it seems...
|
37
37
|
# @@polyglot_options = "--polyglot --experimental-options --single_threaded"
|
38
|
-
@@polyglot_options = "--polyglot --jvm --experimental-options --
|
38
|
+
@@polyglot_options = "--polyglot --jvm --experimental-options --single-threaded"
|
39
39
|
@@libs = "-Ilib/" # -Ir_requires/"
|
40
40
|
|
41
41
|
#----------------------------------------------------------------------------------------
|
@@ -76,12 +76,16 @@ class MakeTask < Rake::TaskLib
|
|
76
76
|
|
77
77
|
end
|
78
78
|
|
79
|
+
|
80
|
+
task :default => "sthda:all"
|
81
|
+
|
79
82
|
geoms = FileList['examples/sthda_ggplot/**/*.rb']
|
80
83
|
specs = FileList['specs/**/*.rb']
|
81
84
|
master_list = FileList['examples/50Plots_MasterList/**/*.rb']
|
82
85
|
islr = FileList['examples/islr/**/*.rb']
|
83
86
|
misc = FileList['examples/misc/**/*.rb']
|
84
87
|
blogs = Dir.entries("blogs")
|
88
|
+
bugs = FileList['bugs/**/*.rb']
|
85
89
|
|
86
90
|
#===========================================================================================
|
87
91
|
# Creates tasks for all specs.
|
@@ -148,7 +152,17 @@ misc.each do |f|
|
|
148
152
|
Desc
|
149
153
|
end
|
150
154
|
|
151
|
-
|
155
|
+
#===========================================================================================
|
156
|
+
# Creates tasks for bug examples
|
157
|
+
#===========================================================================================
|
158
|
+
|
159
|
+
bugs.each do |f|
|
160
|
+
task_name = File.basename(f, ".rb")
|
161
|
+
dir_name = File.dirname(f)
|
162
|
+
MakeTask.new("bugs", dir_name, task_name, false, <<-Desc)
|
163
|
+
Executes misc #{task_name}
|
164
|
+
Desc
|
165
|
+
end
|
152
166
|
|
153
167
|
#===========================================================================================
|
154
168
|
# Creates task for running gknit
|
data/bin/grun
CHANGED
data/bin/gstudio
CHANGED
@@ -5,4 +5,4 @@ Dir.chdir(File.dirname(File.expand_path('.', __FILE__)))
|
|
5
5
|
puts "Loading IRB and Galaaz... Please wait!"
|
6
6
|
|
7
7
|
# exec "ruby --polyglot --jvm -Xsingle_threaded -S pry -r ./gstudio.rb"
|
8
|
-
exec "ruby --polyglot --jvm --experimental-options --
|
8
|
+
exec "ruby --polyglot --jvm --experimental-options --single-threaded -S irb -r ./gstudio.rb"
|