galaaz 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +32 -0
  3. data/Rakefile +177 -0
  4. data/bin/galaaz +8 -0
  5. data/examples/50Plots_MasterList/scatter_plot.rb +51 -0
  6. data/examples/baseball.csv +1 -0
  7. data/examples/baseball.rb +16 -0
  8. data/examples/ggplot.rb +178 -0
  9. data/examples/islr/Figure.jpg +0 -0
  10. data/examples/islr/all.rb +32 -0
  11. data/examples/islr/ch2.spec.rb +148 -0
  12. data/examples/islr/ch3.spec.rb +28 -0
  13. data/examples/islr/ch3_boston.rb +77 -0
  14. data/examples/islr/ch3_multiple_regression.rb +36 -0
  15. data/examples/islr/ch6.spec.rb +64 -0
  16. data/examples/paper/paper.rb +36 -0
  17. data/examples/sthda_ggplot/README.md +38 -0
  18. data/examples/sthda_ggplot/all.rb +68 -0
  19. data/examples/sthda_ggplot/one_variable_continuous/density_gg.rb +52 -0
  20. data/examples/sthda_ggplot/one_variable_continuous/geom_area.rb +61 -0
  21. data/examples/sthda_ggplot/one_variable_continuous/geom_density.rb +77 -0
  22. data/examples/sthda_ggplot/one_variable_continuous/geom_dotplot.rb +69 -0
  23. data/examples/sthda_ggplot/one_variable_continuous/geom_freqpoly.rb +69 -0
  24. data/examples/sthda_ggplot/one_variable_continuous/geom_histogram.rb +62 -0
  25. data/examples/sthda_ggplot/one_variable_continuous/histogram_density.rb +55 -0
  26. data/examples/sthda_ggplot/one_variable_continuous/stat.rb +62 -0
  27. data/examples/sthda_ggplot/one_variable_discrete/bar.rb +54 -0
  28. data/examples/sthda_ggplot/qplots/box_violin_dot.rb +57 -0
  29. data/examples/sthda_ggplot/qplots/scatter_plots.rb +67 -0
  30. data/examples/sthda_ggplot/scatter_gg.rb +60 -0
  31. data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_bin2d.rb +49 -0
  32. data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_density2d.rb +64 -0
  33. data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_hex.rb +52 -0
  34. data/examples/sthda_ggplot/two_variables_cont_cont/geom_point.rb +65 -0
  35. data/examples/sthda_ggplot/two_variables_cont_cont/geom_smooth.rb +66 -0
  36. data/examples/sthda_ggplot/two_variables_cont_cont/misc.rb +83 -0
  37. data/examples/sthda_ggplot/two_variables_cont_function/geom_area.rb +63 -0
  38. data/examples/sthda_ggplot/two_variables_disc_cont/geom_bar.rb +85 -0
  39. data/examples/sthda_ggplot/two_variables_disc_cont/geom_boxplot.rb +62 -0
  40. data/examples/sthda_ggplot/two_variables_disc_cont/geom_dotplot.rb +75 -0
  41. data/examples/sthda_ggplot/two_variables_disc_cont/geom_jitter.rb +74 -0
  42. data/examples/sthda_ggplot/two_variables_disc_cont/geom_line.rb +55 -0
  43. data/examples/sthda_ggplot/two_variables_disc_cont/geom_violin.rb +70 -0
  44. data/examples/sthda_ggplot/two_variables_disc_disc/geom_jitter.rb +40 -0
  45. data/examples/sthda_ggplot/two_variables_error/geom_crossbar.rb +108 -0
  46. data/examples/subsetting.rb +372 -0
  47. data/lib/expression.rb +45 -0
  48. data/lib/galaaz.rb +27 -0
  49. data/lib/r.rb +118 -0
  50. data/lib/r_methods.rb +89 -0
  51. data/lib/rbinary_operators.rb +226 -0
  52. data/lib/rclosure.rb +34 -0
  53. data/lib/rdata_frame.rb +63 -0
  54. data/lib/renvironment.rb +34 -0
  55. data/lib/rexpression.rb +34 -0
  56. data/lib/rindexed_object.rb +68 -0
  57. data/lib/rlanguage.rb +64 -0
  58. data/lib/rlist.rb +72 -0
  59. data/lib/rmatrix.rb +38 -0
  60. data/lib/rmd_indexed_object.rb +43 -0
  61. data/lib/robject.rb +297 -0
  62. data/lib/rpkg.rb +53 -0
  63. data/lib/rsupport.rb +292 -0
  64. data/lib/rsupport_scope.rb +77 -0
  65. data/lib/rsymbol.rb +57 -0
  66. data/lib/ruby_callback.rb +83 -0
  67. data/lib/ruby_extensions.rb +74 -0
  68. data/lib/runary_operators.rb +58 -0
  69. data/lib/rvector.rb +117 -0
  70. data/r_requires/ggplot.rb +31 -0
  71. data/specs/all.rb +45 -0
  72. data/specs/r_dataframe.spec.rb +181 -0
  73. data/specs/r_eval.spec.rb +164 -0
  74. data/specs/r_function.spec.rb +105 -0
  75. data/specs/r_language.spec.rb +135 -0
  76. data/specs/r_list.spec.rb +129 -0
  77. data/specs/r_list_apply.spec.rb +99 -0
  78. data/specs/r_matrix.spec.rb +83 -0
  79. data/specs/r_vector_creation.spec.rb +99 -0
  80. data/specs/r_vector_functions.spec.rb +59 -0
  81. data/specs/r_vector_object.spec.rb +94 -0
  82. data/specs/r_vector_operators.spec.rb +174 -0
  83. data/specs/r_vector_subsetting.spec.rb +136 -0
  84. data/specs/tmp.rb +134 -0
  85. data/version.rb +2 -0
  86. metadata +198 -0
@@ -0,0 +1,68 @@
1
+ # coding: utf-8
2
+
3
+ ##########################################################################################
4
+ # @author Rodrigo Botafogo
5
+ #
6
+ # Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
8
+ # distributions.
9
+ #
10
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
11
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
12
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
13
+ # POSSIBILITY OF SUCH DAMAGE.
14
+ #
15
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
17
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
18
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
19
+ # OR MODIFICATIONS.
20
+ ##########################################################################################
21
+
22
+ require 'galaaz'
23
+ require 'ggplot'
24
+
25
+ # install.packages('quantreg')
26
+ # install.packages('hexbin')
27
+ # Library 'quantreg' is needed in misc
28
+ R.install_and_loads('quantreg', 'hexbin')
29
+
30
+ # Package Hmisc does not yet install on graalvm because of
31
+ # problems with package data.table
32
+ # install.packages('Hmisc')
33
+ # R.install_and_loads('Hmisc')
34
+
35
+ def exec(name)
36
+ puts "=" * (name.size + 12)
37
+ puts "Executing '#{name}'"
38
+ puts "=" * (name.size + 12)
39
+ require_relative name
40
+ end
41
+
42
+ exec "qplots/scatter_plots"
43
+ exec 'qplots/box_violin_dot'
44
+ exec 'one_variable_continuous/histogram_density'
45
+ exec 'scatter_gg'
46
+ exec 'one_variable_continuous/density_gg'
47
+ exec 'one_variable_continuous/geom_area'
48
+ exec 'one_variable_continuous/geom_density'
49
+ exec 'one_variable_continuous/geom_dotplot'
50
+ exec 'one_variable_continuous/geom_freqpoly'
51
+ exec 'one_variable_continuous/geom_histogram'
52
+ exec 'one_variable_continuous/stat'
53
+ exec 'one_variable_discrete/bar'
54
+ exec 'two_variables_cont_cont/geom_point'
55
+ exec 'two_variables_cont_cont/geom_smooth'
56
+ exec 'two_variables_cont_cont/misc'
57
+ exec 'two_variables_cont_bivariate/geom_bin2d'
58
+ exec 'two_variables_cont_bivariate/geom_hex'
59
+ exec 'two_variables_cont_bivariate/geom_density2d'
60
+ exec 'two_variables_cont_function/geom_area'
61
+ exec 'two_variables_disc_cont/geom_boxplot'
62
+ exec 'two_variables_disc_cont/geom_violin'
63
+ exec 'two_variables_disc_cont/geom_dotplot'
64
+ exec 'two_variables_disc_cont/geom_jitter'
65
+ exec 'two_variables_disc_cont/geom_line'
66
+ exec 'two_variables_disc_cont/geom_bar'
67
+ exec 'two_variables_disc_disc/geom_jitter'
68
+ exec 'two_variables_error/geom_crossbar'
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+
3
+ ##########################################################################################
4
+ # @author Rodrigo Botafogo
5
+ #
6
+ # Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
+ # and distribute this software and its documentation, without fee and without a signed
8
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
10
+ # distributions.
11
+ #
12
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
+ # POSSIBILITY OF SUCH DAMAGE.
16
+ #
17
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
+ # OR MODIFICATIONS.
22
+ ##########################################################################################
23
+
24
+ require 'galaaz'
25
+ require 'ggplot'
26
+
27
+ R.set__seed(1234)
28
+
29
+ wdata = R.data__frame(
30
+ sex: R.c("F", "M").rep(each: 200).factor,
31
+ weight: R.c(R.rnorm(200, 55), R.rnorm(200,58)))
32
+
33
+ puts wdata.head
34
+
35
+ R.awt
36
+
37
+ # Use geometry function
38
+ print wdata.ggplot(E.aes(x: :weight)) + R.geom_density
39
+
40
+ sleep(2)
41
+ R.grid__newpage
42
+
43
+ # OR use stat function
44
+ print wdata.ggplot(E.aes(x: :weight)) + R.stat_density
45
+
46
+ sleep(2)
47
+ R.grid__newpage
48
+
49
+ # a = gets.chomp
50
+
51
+ # removes the window and creates a new one
52
+ R.dev__off
@@ -0,0 +1,61 @@
1
+ # coding: utf-8
2
+
3
+ ##########################################################################################
4
+ # @author Rodrigo Botafogo
5
+ #
6
+ # Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
+ # and distribute this software and its documentation, without fee and without a signed
8
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
10
+ # distributions.
11
+ #
12
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
+ # POSSIBILITY OF SUCH DAMAGE.
16
+ #
17
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
+ # OR MODIFICATIONS.
22
+ ##########################################################################################
23
+
24
+ require 'galaaz'
25
+ require 'ggplot'
26
+
27
+ R.set__seed(1234)
28
+
29
+ wdata = R.data__frame(
30
+ sex: R.c("F", "M").rep(each: 200).factor,
31
+ weight: R.c(R.rnorm(200, 55), R.rnorm(200,58)))
32
+
33
+ puts wdata.head
34
+
35
+ # We start by creating a plot, named 'a', that we’ll finish next by adding layers
36
+ a = wdata.ggplot(E.aes(x: :weight))
37
+
38
+ R.awt
39
+
40
+ # Basic plot
41
+ print a + R.geom_area(stat: "bin")
42
+
43
+ sleep(2)
44
+ R.grid__newpage
45
+
46
+ # change fill colors by sex
47
+ print a + R.geom_area(E.aes(fill: :sex),
48
+ stat: "bin", alpha: 0.6) +
49
+ R.theme_classic
50
+
51
+
52
+ sleep(2)
53
+ R.grid__newpage
54
+
55
+ print a + R.geom_area(E.aes_string(y: "..density.."), stat: "bin")
56
+ sleep(2)
57
+
58
+ # a = gets.chomp
59
+
60
+ # removes the window and creates a new one
61
+ R.dev__off
@@ -0,0 +1,77 @@
1
+ # coding: utf-8
2
+
3
+ ##########################################################################################
4
+ # @author Rodrigo Botafogo
5
+ #
6
+ # Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
+ # and distribute this software and its documentation, without fee and without a signed
8
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
10
+ # distributions.
11
+ #
12
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
+ # POSSIBILITY OF SUCH DAMAGE.
16
+ #
17
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
+ # OR MODIFICATIONS.
22
+ ##########################################################################################
23
+
24
+ require 'galaaz'
25
+ require 'ggplot'
26
+
27
+ R.set__seed(1234)
28
+
29
+ wdata = R.data__frame(
30
+ sex: R.c("F", "M").rep(each: 200).factor,
31
+ weight: R.c(R.rnorm(200, 55), R.rnorm(200,58)))
32
+
33
+ puts wdata.head
34
+
35
+ # We start by creating a plot, named 'a', that we’ll finish next by adding layers
36
+ a = wdata.ggplot(E.aes(x: :weight))
37
+
38
+ # Aggregate the data by sex
39
+ mu = R.aggregate(wdata.weight, by: R.list(wdata.sex), FUN: :mean)
40
+ mu.names = R.c("sex", "grp_mean")
41
+ puts mu
42
+
43
+ R.awt
44
+
45
+ # Basic plot
46
+ print a + R.geom_density
47
+
48
+ sleep(2)
49
+ R.grid__newpage
50
+
51
+ # change line colors by sex
52
+ print a + R.geom_density(E.aes(color: :sex))
53
+
54
+ sleep(2)
55
+ R.grid__newpage
56
+
57
+ # Change fill color by sex
58
+ # Use semi-transparent fill: alpha = 0.4
59
+ print a + R.geom_density(E.aes(fill: :sex), alpha: 0.4)
60
+
61
+ sleep(2)
62
+ R.grid__newpage
63
+
64
+ # Add mean line and Change color manually
65
+ # Note that Ruby requires hash parameters to come at the end of the parameter
66
+ # list, so data: mu, needs to come after E.aes
67
+ print a + R.geom_density(E.aes(color: :sex)) +
68
+ R.geom_vline(E.aes(xintercept: :grp_mean, color: :sex), data: mu) +
69
+ R.scale_color_manual(values: R.c("#999999", "#E69F00"))
70
+
71
+ sleep(2)
72
+ R.grid__newpage
73
+
74
+ # a = gets.chomp
75
+
76
+ # removes the window and creates a new one
77
+ R.dev__off
@@ -0,0 +1,69 @@
1
+ # coding: utf-8
2
+
3
+ ##########################################################################################
4
+ # @author Rodrigo Botafogo
5
+ #
6
+ # Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
+ # and distribute this software and its documentation, without fee and without a signed
8
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
10
+ # distributions.
11
+ #
12
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
+ # POSSIBILITY OF SUCH DAMAGE.
16
+ #
17
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
+ # OR MODIFICATIONS.
22
+ ##########################################################################################
23
+
24
+ require 'galaaz'
25
+ require 'ggplot'
26
+
27
+ R.set__seed(1234)
28
+
29
+ wdata = R.data__frame(
30
+ sex: R.c("F", "M").rep(each: 200).factor,
31
+ weight: R.c(R.rnorm(200, 55), R.rnorm(200,58)))
32
+
33
+ puts wdata.head
34
+
35
+ # We start by creating a plot, named 'a', that we’ll finish next by adding layers
36
+ a = wdata.ggplot(E.aes(x: :weight))
37
+
38
+ # Aggregate the data by sex
39
+ mu = R.aggregate(wdata.weight, by: R.list(wdata.sex), FUN: :mean)
40
+ mu.names = R.c("sex", "grp_mean")
41
+ puts mu
42
+
43
+ R.awt
44
+
45
+ # Basic plot
46
+ print a + R.geom_dotplot
47
+
48
+ # Basic plot
49
+
50
+ sleep(2)
51
+ R.grid__newpage
52
+
53
+ # change fill and color by sex
54
+ print a + R.geom_dotplot(E.aes(fill: :sex))
55
+
56
+ sleep(2)
57
+ R.grid__newpage
58
+
59
+ # Change fill color manually
60
+ print a + R.geom_dotplot(E.aes(fill: :sex)) +
61
+ R.scale_fill_manual(values: R.c("#999999", "#E69F00"))
62
+
63
+ sleep(2)
64
+ R.grid__newpage
65
+
66
+ # a = gets.chomp
67
+
68
+ # removes the window and creates a new one
69
+ R.dev__off
@@ -0,0 +1,69 @@
1
+ # coding: utf-8
2
+
3
+ ##########################################################################################
4
+ # @author Rodrigo Botafogo
5
+ #
6
+ # Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
+ # and distribute this software and its documentation, without fee and without a signed
8
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
10
+ # distributions.
11
+ #
12
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
+ # POSSIBILITY OF SUCH DAMAGE.
16
+ #
17
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
+ # OR MODIFICATIONS.
22
+ ##########################################################################################
23
+
24
+ require 'galaaz'
25
+ require 'ggplot'
26
+
27
+ R.set__seed(1234)
28
+
29
+ wdata = R.data__frame(
30
+ sex: R.c("F", "M").rep(each: 200).factor,
31
+ weight: R.c(R.rnorm(200, 55), R.rnorm(200,58)))
32
+
33
+ puts wdata.head
34
+
35
+ # We start by creating a plot, named 'a', that we’ll finish next by adding layers
36
+ a = wdata.ggplot(E.aes(x: :weight))
37
+
38
+ # Aggregate the data by sex
39
+ mu = R.aggregate(wdata.weight, by: R.list(wdata.sex), FUN: :mean)
40
+ mu.names = R.c("sex", "grp_mean")
41
+ puts mu
42
+
43
+ R.awt
44
+
45
+ # Basic plot
46
+ print a + R.geom_freqpoly
47
+
48
+ sleep(2)
49
+ R.grid__newpage
50
+
51
+ # change y axis to density value
52
+ # and change theme
53
+ print a + R.geom_freqpoly(E.aes_string(y: "..density..")) +
54
+ R.theme_minimal
55
+
56
+ sleep(2)
57
+ R.grid__newpage
58
+
59
+ # change color and linetype by sex
60
+ print a + R.geom_freqpoly(E.aes(color: :sex, linetype: :sex)) +
61
+ R.theme_minimal
62
+
63
+ sleep(2)
64
+ R.grid__newpage
65
+
66
+ # a = gets.chomp
67
+
68
+ # removes the window and creates a new one
69
+ R.dev__off
@@ -0,0 +1,62 @@
1
+ # coding: utf-8
2
+
3
+ ##########################################################################################
4
+ # @author Rodrigo Botafogo
5
+ #
6
+ # Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
+ # and distribute this software and its documentation, without fee and without a signed
8
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
10
+ # distributions.
11
+ #
12
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
+ # POSSIBILITY OF SUCH DAMAGE.
16
+ #
17
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
+ # OR MODIFICATIONS.
22
+ ##########################################################################################
23
+
24
+ require 'galaaz'
25
+ require 'ggplot'
26
+
27
+ R.set__seed(1234)
28
+
29
+ wdata = R.data__frame(
30
+ sex: R.c("F", "M").rep(each: 200).factor,
31
+ weight: R.c(R.rnorm(200, 55), R.rnorm(200,58)))
32
+
33
+ puts wdata.head
34
+
35
+ # We start by creating a plot, named 'a', that we’ll finish next by adding layers
36
+ a = wdata.ggplot(E.aes(x: :weight))
37
+
38
+ # Aggregate the data by sex
39
+ mu = R.aggregate(wdata.weight, by: R.list(wdata.sex), FUN: :mean)
40
+ mu.names = R.c("sex", "grp_mean")
41
+ puts mu
42
+
43
+ R.awt
44
+
45
+ # Basic plot
46
+ print a + R.geom_histogram
47
+
48
+ sleep(2)
49
+ R.grid__newpage
50
+
51
+ # change line colors by sex
52
+ print a + R.geom_histogram(E.aes(color: :sex), fill: "white",
53
+ position: "dodge")
54
+
55
+ sleep(2)
56
+ R.grid__newpage
57
+
58
+
59
+ # a = gets.chomp
60
+
61
+ # removes the window and creates a new one
62
+ R.dev__off