galaaz 0.5.0 → 2.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/LICENSE +0 -0
- data/README.md +1360 -636
- data/Rakefile +61 -41
- data/bin/galaaz-bootstrap +137 -0
- data/bin/galaaz-jruby +14 -0
- data/bin/galaaz_jruby_env.inc.sh +6 -0
- data/bin/gbookdown +64 -0
- data/bin/gknit +84 -13
- data/bin/gknit-draft.rb +0 -0
- data/bin/gstudio +5 -3
- data/bin/gstudio_irb.rb +0 -0
- data/bin/gstudio_pry.rb +0 -0
- data/bin/install-tinytex +6 -0
- data/bin/run_all_rspec +43 -0
- data/bin/run_example +14 -0
- data/bin/run_old_rspec +19 -0
- data/bin/run_rspec +23 -0
- data/bin/run_rspec_subset +38 -0
- data/bin/run_slow_rspec +19 -0
- data/blogs/R-on-Rails-Planning-Document.md +940 -0
- data/blogs/README.md +100 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +38 -66
- data/blogs/galaaz_ggplot/galaaz_ggplot.log +754 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.md +115 -155
- data/blogs/galaaz_ggplot/galaaz_ggplot.tex +607 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/midwest_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/scatter_plot_rb.png +0 -0
- data/blogs/galaaz_ggplot/midwest.Rmd +3 -3
- data/blogs/galaaz_ggplot/midwest_external_png +0 -0
- data/blogs/gknit/gknit.Rmd +47 -52
- data/blogs/gknit/gknit.md +1430 -0
- data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
- data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
- data/blogs/gknit/lst.rds +0 -0
- data/blogs/gknit/model.rb +1 -1
- data/blogs/gknit/stats.bib +0 -0
- data/blogs/manual/include_model_local_repro.Rmd +14 -0
- data/blogs/manual/include_model_local_repro.md +75 -0
- data/blogs/manual/lst.rds +0 -0
- data/blogs/manual/manual.Rmd +852 -239
- data/blogs/manual/manual.log +1786 -0
- data/blogs/manual/manual.md +1360 -636
- data/blogs/manual/manual.tex +1883 -1161
- data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
- data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
- data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
- data/blogs/manual/model.rb +1 -1
- data/blogs/nse_dplyr/nse_dplyr.Rmd +84 -111
- data/blogs/nse_dplyr/nse_dplyr.log +928 -0
- data/blogs/nse_dplyr/nse_dplyr.md +198 -229
- data/blogs/oh_my/not_so.rb +0 -0
- data/blogs/oh_my/oh_my.Rmd +1234 -25
- data/blogs/oh_my/oh_my.log +804 -0
- data/blogs/oh_my/oh_my.md +1663 -86
- data/blogs/oh_my/oh_my.tex +821 -0
- data/blogs/oh_my/old.Rmd +15 -14
- data/blogs/ruby_plot/ruby_plot.Rmd +58 -82
- data/blogs/ruby_plot/ruby_plot.log +885 -0
- data/blogs/ruby_plot/ruby_plot.md +71 -102
- data/blogs/ruby_plot/ruby_plot.tex +940 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.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/blogs/ruby_plot/ruby_plot_files/figure-latex/dose_len.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
- data/blogs/test/test.Rmd +14 -0
- data/examples/50Plots_MasterList/Images/midwest-scatterplot.PNG +0 -0
- data/examples/50Plots_MasterList/ScatterPlot.rb +0 -0
- data/examples/50Plots_MasterList/scatter_plot.rb +0 -0
- data/examples/Bibliography/master.bib +0 -0
- data/examples/Bibliography/stats.bib +0 -0
- data/examples/R/calc.R +0 -0
- data/examples/R/java_interop.R +0 -0
- data/examples/bioconductor_deseq2_airway/Documentation/DESeq2-airway-walkthrough.md +56 -0
- data/examples/bioconductor_deseq2_airway/bench_galaaz_three_same_process.rb +53 -0
- data/examples/bioconductor_deseq2_airway/bench_r_three_same_process.R +34 -0
- data/examples/bioconductor_deseq2_airway/deseq2_airway_galaaz.rb +33 -0
- data/examples/bioconductor_deseq2_airway/deseq2_airway_galaaz_optimized.rb +34 -0
- data/examples/bioconductor_deseq2_airway/deseq2_airway_minimal.R +30 -0
- data/examples/bioconductor_deseq2_airway/deseq2_airway_pipeline_for_bench.R +36 -0
- data/examples/islr/all.rb +13 -0
- data/examples/islr/ch2.spec.rb +37 -7
- data/examples/islr/ch3.spec.rb +11 -2
- data/examples/islr/ch3_boston.rb +27 -0
- data/examples/islr/ch3_multiple_regression.rb +0 -0
- data/examples/islr/ch6.spec.rb +24 -1
- data/examples/islr/x_y_rnorm.jpg +0 -0
- data/examples/latex_templates/Test-acm_article/acm_proc_article-sp.cls +0 -0
- data/examples/latex_templates/Test-acm_article/sigproc.bib +0 -0
- data/examples/latex_templates/Test-acs_article/acs-Test-acs_article.bib +0 -0
- data/examples/latex_templates/Test-acs_article/acs-my_output.bib +0 -0
- data/examples/latex_templates/Test-aea_article/BibFile.bib +0 -0
- data/examples/latex_templates/Test-aea_article/Test-aea_article.Rmd +0 -0
- data/examples/latex_templates/Test-aea_article/references.bib +0 -0
- data/examples/latex_templates/Test-amq_article/Test-amq_article.Rmd +0 -0
- data/examples/latex_templates/Test-amq_article/Test-amq_article.pdfsync +0 -0
- data/examples/latex_templates/Test-ieee_article/IEEEtran.bst +0 -0
- data/examples/latex_templates/Test-ieee_article/mybibfile.bib +0 -0
- data/examples/latex_templates/Test-rjournal_article/RJournal.sty +0 -0
- data/examples/latex_templates/Test-rjournal_article/RJreferences.bib +0 -0
- data/examples/latex_templates/Test-rjournal_article/Test-rjournal_article.Rmd +0 -0
- data/examples/misc/baseball.csv +0 -0
- data/examples/misc/ggplot.rb +3 -2
- data/examples/misc/moneyball.rb +0 -0
- data/examples/misc/subsetting.rb +0 -0
- data/examples/multithread_shards_to_r/shards_to_r.rb +67 -0
- data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.Rmd +0 -0
- data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.Rmd +0 -0
- data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.Rmd +0 -0
- data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.Rmd +0 -0
- data/examples/rmarkdown/svm-rmarkdown-syllabus-example/attend-grade-relationships.csv +0 -0
- data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.Rmd +0 -0
- data/examples/rmarkdown/svm-xaringan-example/svm-xaringan-example.Rmd +0 -0
- data/examples/sthda_ggplot/README.md +0 -0
- data/examples/sthda_ggplot/RUN.md +41 -0
- data/examples/sthda_ggplot/all.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/density_gg.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_area.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_density.rb +2 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_dotplot.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_freqpoly.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_histogram.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/histogram_density.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/stat.rb +0 -0
- data/examples/sthda_ggplot/one_variable_discrete/bar.rb +0 -0
- data/examples/sthda_ggplot/qplots/box_violin_dot.rb +0 -0
- data/examples/sthda_ggplot/qplots/scatter_plots.rb +0 -0
- data/examples/sthda_ggplot/scatter_gg.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_bin2d.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_density2d.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_hex.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_cont/geom_point.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_cont/geom_smooth.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_cont/misc.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_function/geom_area.rb +4 -3
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_bar.rb +0 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_boxplot.rb +0 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_dotplot.rb +0 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_jitter.rb +0 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_line.rb +0 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_violin.rb +0 -0
- data/examples/sthda_ggplot/two_variables_disc_disc/geom_jitter.rb +0 -0
- data/examples/sthda_ggplot/two_variables_error/geom_crossbar.rb +0 -0
- data/ext/new_bridge/Makefile +46 -0
- data/ext/new_bridge/galaaz_gatekeeper_phase0.cpp +12 -0
- data/ext/new_bridge/galaaz_gatekeeper_phase1.cpp +1639 -0
- data/lib/R_interface/galaaz_device.R +20 -0
- data/lib/R_interface/include_engine.R +109 -0
- data/lib/R_interface/new_bridge_adapter.rb +824 -0
- data/lib/R_interface/r.rb +177 -25
- data/lib/R_interface/r_arrow.rb +113 -0
- data/lib/R_interface/r_libs.R +3 -3
- data/lib/R_interface/r_methods.rb +13 -126
- data/lib/R_interface/r_module_s.rb +0 -0
- data/lib/R_interface/rbinary_operators.rb +20 -2
- data/lib/R_interface/rclosure.rb +5 -1
- data/lib/R_interface/rdata_frame.rb +34 -70
- data/lib/R_interface/rdevice.rb +125 -0
- data/lib/R_interface/rdevices.R +0 -0
- data/lib/R_interface/renvironment.rb +10 -4
- data/lib/R_interface/rexpression.rb +5 -1
- data/lib/R_interface/rindexed_object.rb +41 -13
- data/lib/R_interface/rlanguage.rb +20 -62
- data/lib/R_interface/rlist.rb +115 -25
- data/lib/R_interface/rlogical_operators.rb +0 -0
- data/lib/R_interface/rmatrix.rb +2 -11
- data/lib/R_interface/rmd_indexed_object.rb +5 -1
- data/lib/R_interface/robject.rb +348 -290
- data/lib/R_interface/rpkg.rb +0 -0
- data/lib/R_interface/rsupport.rb +609 -328
- data/lib/R_interface/rsupport_scope.rb +2 -1
- data/lib/R_interface/rsymbol.rb +50 -0
- data/lib/R_interface/ruby_callback.rb +2 -3
- data/lib/R_interface/ruby_extensions.rb +225 -175
- data/lib/R_interface/runary_operators.rb +0 -0
- data/lib/R_interface/rvector.rb +147 -31
- data/lib/galaaz.rb +0 -0
- data/lib/galaaz_jruby.rb +22 -0
- data/lib/gknit/diagnostics.rb +50 -0
- data/lib/gknit/draft.rb +23 -17
- data/lib/gknit/include_engine.rb +15 -7
- data/lib/gknit/knitr_engine.rb +223 -74
- data/lib/gknit/rb_engine.rb +3 -3
- data/lib/gknit/ruby_engine.rb +0 -0
- data/lib/gknit.rb +1 -0
- data/lib/new_bridge/bootstrap/windows_bootstrap.rb +285 -0
- data/lib/new_bridge/envelope.rb +51 -0
- data/lib/new_bridge/eval_result.rb +26 -0
- data/lib/new_bridge/framing.rb +39 -0
- data/lib/new_bridge/instance_pool_client.rb +38 -0
- data/lib/new_bridge/r_instance_manager.rb +404 -0
- data/lib/new_bridge/session_client.rb +530 -0
- data/lib/new_bridge/tcp_framed.rb +44 -0
- data/lib/new_bridge.rb +9 -0
- data/lib/util/exec_ruby.rb +95 -20
- data/lib/util/inline_file.rb +35 -30
- data/new_bridge_specs/benchmark_phase5_5_unboxing_spec.rb +96 -0
- data/new_bridge_specs/eval_r_async_spec.rb +113 -0
- data/new_bridge_specs/integration_phase5_1_concurrent_spec.rb +50 -0
- data/new_bridge_specs/integration_phase5_1_eval_spec.rb +16 -0
- data/new_bridge_specs/integration_phase5_1_r_api_spec.rb +25 -0
- data/new_bridge_specs/integration_phase5_1_smoke_spec.rb +31 -0
- data/new_bridge_specs/integration_phase5_2_dataframe_unboxing_spec.rb +19 -0
- data/new_bridge_specs/integration_phase5_2_handle_eval_unboxing_spec.rb +25 -0
- data/new_bridge_specs/integration_phase5_3_callback_args_spec.rb +28 -0
- data/new_bridge_specs/integration_phase5_3_callback_error_spec.rb +22 -0
- data/new_bridge_specs/integration_phase5_3_callback_timeout_spec.rb +28 -0
- data/new_bridge_specs/integration_phase5_3_callbacks_smoke_spec.rb +22 -0
- data/new_bridge_specs/integration_phase5_3_edge_cases_spec.rb +52 -0
- data/new_bridge_specs/integration_phase5_3_nested_spec.rb +30 -0
- data/new_bridge_specs/integration_phase5_4_concurrent_sessions_spec.rb +53 -0
- data/new_bridge_specs/integration_phase5_4_nested_session_callbacks_spec.rb +49 -0
- data/new_bridge_specs/integration_phase5_4_session_routing_spec.rb +38 -0
- data/new_bridge_specs/integration_phase5_5_stress_concurrency_spec.rb +52 -0
- data/new_bridge_specs/integration_phase5_5_unbox_walk_spec.rb +46 -0
- data/new_bridge_specs/phase0_protocol_spec.rb +96 -0
- data/new_bridge_specs/phase1_req_ret_spec.rb +66 -0
- data/new_bridge_specs/phase2_multi_instance_spec.rb +67 -0
- data/new_bridge_specs/phase3_callbacks_spec.rb +71 -0
- data/new_bridge_specs/phase4_2_hardening_spec.rb +252 -0
- data/new_bridge_specs/phase4_3_r_instance_manager_spec.rb +85 -0
- data/new_bridge_specs/phase4_nested_callbacks_spec.rb +123 -0
- data/r_requires/ggplot.rb +0 -0
- data/r_requires/knitr.rb +0 -0
- data/specs/all.rb +15 -11
- data/specs/arrow_from_ruby_batches_spec.rb +50 -0
- data/specs/arrow_semantics_spec.rb +64 -0
- data/specs/bridge_concurrent_spec.rb +46 -0
- data/specs/bridge_nested_spec.rb +25 -0
- data/specs/dataframe_semantics_spec.rb +122 -0
- data/specs/dataframe_single_index_logical_filter_spec.rb +21 -0
- data/specs/dispatch_probe_cache_spec.rb +38 -0
- data/specs/dispatch_probe_error_class_fallback_spec.rb +20 -0
- data/specs/dispatch_probe_fallback_spec.rb +18 -0
- data/specs/environment_semantics_spec.rb +89 -0
- data/specs/field_access_spec.rb +31 -0
- data/specs/figures/bg.jpeg +0 -0
- data/specs/figures/bg.png +0 -0
- data/specs/figures/bg.svg +168 -57
- data/specs/figures/dose_len.png +0 -0
- data/specs/figures/no_args.jpeg +0 -0
- data/specs/figures/no_args.png +0 -0
- data/specs/figures/no_args.svg +168 -57
- data/specs/figures/width_height.jpeg +0 -0
- data/specs/figures/width_height.png +0 -0
- data/specs/figures/width_height_units1.jpeg +0 -0
- data/specs/figures/width_height_units1.png +0 -0
- data/specs/figures/width_height_units2.jpeg +0 -0
- data/specs/figures/width_height_units2.png +0 -0
- data/specs/formula_semantics_spec.rb +81 -0
- data/specs/galaaz_util_exec_ruby_spec.rb +85 -0
- data/specs/galaaz_util_inline_file_spec.rb +54 -0
- data/specs/gknit_cli_option_permutation_spec.rb +24 -0
- data/specs/gknit_include_engine_spec.rb +72 -0
- data/specs/gknit_install_timeout_report_spec.rb +69 -0
- data/specs/gknit_internal_error_report_spec.rb +57 -0
- data/specs/gknit_vector_map_output_spec.rb +59 -0
- data/specs/globalenv_guardrail_spec.rb +52 -0
- data/specs/language_expression_semantics_spec.rb +145 -0
- data/specs/list_semantics_spec.rb +111 -0
- data/specs/new_bridge_bulk_dataframe_transfer_spec.rb +44 -0
- data/specs/new_bridge_bulk_vector_transfer_spec.rb +73 -0
- data/specs/new_bridge_callback_timeout_spec.rb +69 -0
- data/specs/new_bridge_eval_r_fallback_spec.rb +55 -0
- data/specs/nil_null_spec.rb +42 -0
- data/specs/object_build_phase2_spec.rb +53 -0
- data/specs/phase1_callback_bridge_spec.rb +84 -0
- data/specs/phase2_gknit_generic_rendering_guardrail_spec.rb +46 -0
- data/specs/phase2_gknit_no_raw_code_leakage_spec.rb +43 -0
- data/specs/phase3_gknit_generic_graphics_capture_spec.rb +71 -0
- data/specs/plot_device_semantics_spec.rb +28 -0
- data/specs/plot_snapshot_semantics_spec.rb +58 -0
- data/specs/protocol_result_spec.rb +236 -0
- data/specs/r_batch_fail_fast_spec.rb +47 -0
- data/specs/r_bridge_bootstrap_spec.rb +11 -0
- data/specs/r_devices.spec.rb +1 -1
- data/specs/r_eval.spec.rb +16 -18
- data/specs/r_function.spec.rb +1 -1
- data/specs/r_instance_manager_spec.rb +285 -0
- data/specs/r_list_apply.spec.rb +15 -15
- data/specs/r_matrix.spec.rb +0 -0
- data/specs/r_nse.spec.rb +5 -5
- data/specs/r_object_send_dispatch_spec.rb +13 -0
- data/specs/r_vector_comparator_spec.rb +8 -0
- data/specs/r_vector_creation.spec.rb +0 -0
- data/specs/r_vector_functions.spec.rb +0 -0
- data/specs/r_vector_object.spec.rb +0 -0
- data/specs/r_vector_operators.spec.rb +0 -0
- data/specs/r_vector_structured_scalar_reads_spec.rb +35 -0
- data/specs/r_vector_subsetting.spec.rb +0 -0
- data/specs/range_helper_spec.rb +21 -0
- data/specs/rsupport_scope_spec.rb +28 -0
- data/specs/rsupport_var_name_thread_safety_spec.rb +24 -0
- data/specs/scalar_character_spec.rb +44 -0
- data/specs/scoped_symbol_dsl_refinement_spec.rb +40 -0
- data/specs/session_env_bridge_spec.rb +25 -0
- data/specs/simplecov_bootstrap_spec.rb +10 -0
- data/specs/spec_helper.rb +10 -0
- data/specs/tmp.rb +0 -0
- data/specs/unboxing_recursion_regression_spec.rb +30 -0
- data/specs/unboxing_spec.rb +49 -0
- data/specs/verify_callbacks.rb +42 -0
- data/sty/galaaz.sty +0 -0
- data/version.rb +1 -1
- metadata +194 -64
- data/blogs/galaaz_ggplot/galaaz_ggplot.html +0 -520
- data/blogs/galaaz_ggplot/galaaz_ggplot.pdf +0 -0
- data/blogs/galaaz_ggplot/midwest.html +0 -188
- data/blogs/gknit/gknit.html +0 -2266
- data/blogs/gknit/gknit.pdf +0 -0
- data/blogs/manual/manual.html +0 -4638
- data/blogs/manual/manual.pdf +0 -0
- data/blogs/manual/manual_files/figure-latex/diverging_bar.pdf +0 -0
- data/blogs/nse_dplyr/nse_dplyr.html +0 -878
- data/blogs/nse_dplyr/nse_dplyr.pdf +0 -0
- data/blogs/oh_my/oh_my.html +0 -568
- data/blogs/ruby_plot/ruby_plot.html +0 -544
- data/blogs/ruby_plot/ruby_plot.pdf +0 -0
- data/examples/latex_templates/Test-acs_article/Test-acs_article.pdf +0 -0
- data/examples/latex_templates/Test-aea_article/Test-aea_article.pdf +0 -0
- data/examples/latex_templates/Test-amq_article/Test-amq_article.pdf +0 -0
- data/examples/latex_templates/Test-amq_article/pics/Figure2.pdf +0 -0
- data/examples/latex_templates/Test-asa_article/Test-asa_article.pdf +0 -0
- data/examples/latex_templates/Test-ieee_article/Test-ieee_article.pdf +0 -0
- data/examples/latex_templates/Test-rjournal_article/RJwrapper.pdf +0 -0
- data/examples/latex_templates/Test-springer_article/Test-springer_article.pdf +0 -0
- data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.pdf +0 -0
- data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.pdf +0 -0
- data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.pdf +0 -0
- data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.pdf +0 -0
- data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.pdf +0 -0
- data/specs/r_dataframe.spec.rb +0 -379
- data/specs/r_environment.spec.rb +0 -140
- data/specs/r_formula.spec.rb +0 -232
- data/specs/r_language.spec.rb +0 -112
- data/specs/r_list.spec.rb +0 -293
- data/specs/r_plots.spec.rb +0 -72
- data/specs/ruby_expression.spec.rb +0 -316
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
% Options for packages loaded elsewhere
|
|
2
|
+
\PassOptionsToPackage{unicode}{hyperref}
|
|
3
|
+
\PassOptionsToPackage{hyphens}{url}
|
|
4
|
+
\documentclass[
|
|
5
|
+
11pt,
|
|
6
|
+
]{article}
|
|
7
|
+
\usepackage{xcolor}
|
|
8
|
+
\usepackage[margin=1in]{geometry}
|
|
9
|
+
\usepackage{amsmath,amssymb}
|
|
10
|
+
\setcounter{secnumdepth}{5}
|
|
11
|
+
\usepackage{iftex}
|
|
12
|
+
\ifPDFTeX
|
|
13
|
+
\usepackage[T1]{fontenc}
|
|
14
|
+
\usepackage[utf8]{inputenc}
|
|
15
|
+
\usepackage{textcomp} % provide euro and other symbols
|
|
16
|
+
\else % if luatex or xetex
|
|
17
|
+
\usepackage{unicode-math} % this also loads fontspec
|
|
18
|
+
\defaultfontfeatures{Scale=MatchLowercase}
|
|
19
|
+
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
|
|
20
|
+
\fi
|
|
21
|
+
\usepackage{lmodern}
|
|
22
|
+
\ifPDFTeX\else
|
|
23
|
+
% xetex/luatex font selection
|
|
24
|
+
\fi
|
|
25
|
+
% Use upquote if available, for straight quotes in verbatim environments
|
|
26
|
+
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
|
|
27
|
+
\IfFileExists{microtype.sty}{% use microtype if available
|
|
28
|
+
\usepackage[]{microtype}
|
|
29
|
+
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
|
|
30
|
+
}{}
|
|
31
|
+
\makeatletter
|
|
32
|
+
\@ifundefined{KOMAClassName}{% if non-KOMA class
|
|
33
|
+
\IfFileExists{parskip.sty}{%
|
|
34
|
+
\usepackage{parskip}
|
|
35
|
+
}{% else
|
|
36
|
+
\setlength{\parindent}{0pt}
|
|
37
|
+
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
|
|
38
|
+
}{% if KOMA class
|
|
39
|
+
\KOMAoptions{parskip=half}}
|
|
40
|
+
\makeatother
|
|
41
|
+
\usepackage{color}
|
|
42
|
+
\usepackage{fancyvrb}
|
|
43
|
+
\newcommand{\VerbBar}{|}
|
|
44
|
+
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
|
|
45
|
+
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
|
|
46
|
+
% Add ',fontsize=\small' for more characters per line
|
|
47
|
+
\usepackage{framed}
|
|
48
|
+
\definecolor{shadecolor}{RGB}{248,248,248}
|
|
49
|
+
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
|
|
50
|
+
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
|
|
51
|
+
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
|
52
|
+
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
|
|
53
|
+
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
|
|
54
|
+
\newcommand{\BuiltInTok}[1]{#1}
|
|
55
|
+
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
|
|
56
|
+
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
|
|
57
|
+
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
|
58
|
+
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
|
|
59
|
+
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
|
|
60
|
+
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
|
|
61
|
+
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
|
|
62
|
+
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
|
63
|
+
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
|
|
64
|
+
\newcommand{\ExtensionTok}[1]{#1}
|
|
65
|
+
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
|
|
66
|
+
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
|
|
67
|
+
\newcommand{\ImportTok}[1]{#1}
|
|
68
|
+
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
|
69
|
+
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
|
|
70
|
+
\newcommand{\NormalTok}[1]{#1}
|
|
71
|
+
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
|
|
72
|
+
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
|
|
73
|
+
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
|
|
74
|
+
\newcommand{\RegionMarkerTok}[1]{#1}
|
|
75
|
+
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
|
|
76
|
+
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
|
|
77
|
+
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
|
|
78
|
+
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
|
|
79
|
+
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
|
|
80
|
+
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
|
81
|
+
\usepackage{graphicx}
|
|
82
|
+
\makeatletter
|
|
83
|
+
\newsavebox\pandoc@box
|
|
84
|
+
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
|
|
85
|
+
\sbox\pandoc@box{#1}%
|
|
86
|
+
\Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
|
|
87
|
+
\Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
|
|
88
|
+
\ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
|
|
89
|
+
\ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
|
|
90
|
+
\else\usebox{\pandoc@box}%
|
|
91
|
+
\fi%
|
|
92
|
+
}
|
|
93
|
+
% Set default figure placement to htbp
|
|
94
|
+
\def\fps@figure{htbp}
|
|
95
|
+
\makeatother
|
|
96
|
+
\setlength{\emergencystretch}{3em} % prevent overfull lines
|
|
97
|
+
\providecommand{\tightlist}{%
|
|
98
|
+
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
|
|
99
|
+
% usar portugues do Brasil
|
|
100
|
+
% \usepackage[brazilian]{babel}
|
|
101
|
+
\usepackage[utf8]{inputenc}
|
|
102
|
+
|
|
103
|
+
\usepackage{geometry}
|
|
104
|
+
\geometry{a4paper, top=1in}
|
|
105
|
+
|
|
106
|
+
% needed for kableExtra
|
|
107
|
+
\usepackage{longtable}
|
|
108
|
+
\usepackage{multirow}
|
|
109
|
+
\usepackage[table]{xcolor}
|
|
110
|
+
\usepackage{wrapfig}
|
|
111
|
+
\usepackage{float}
|
|
112
|
+
\usepackage{colortbl}
|
|
113
|
+
\usepackage{pdflscape}
|
|
114
|
+
\usepackage{tabu}
|
|
115
|
+
\usepackage{threeparttable}
|
|
116
|
+
\usepackage[normalem]{ulem}
|
|
117
|
+
|
|
118
|
+
\usepackage{bbm}
|
|
119
|
+
\usepackage{booktabs}
|
|
120
|
+
\usepackage{expex}
|
|
121
|
+
|
|
122
|
+
\usepackage{graphicx}
|
|
123
|
+
|
|
124
|
+
\usepackage{fancyhdr}
|
|
125
|
+
% set the header and foot style
|
|
126
|
+
% style 'fancy' adds the section name on the header
|
|
127
|
+
% and the page number on the footer
|
|
128
|
+
\pagestyle{fancy}
|
|
129
|
+
|
|
130
|
+
% style 'fancyhf' leaves header and footer empty
|
|
131
|
+
%\fancyhf{}
|
|
132
|
+
|
|
133
|
+
% sets the left head element to \rightmark, which contains the
|
|
134
|
+
% current section (\leftmark is the current chapter)
|
|
135
|
+
%\fancyhead[L]{\rightmark} .
|
|
136
|
+
|
|
137
|
+
% sets the right head element to the page number.
|
|
138
|
+
% \fancyhead[R]{\thepage}
|
|
139
|
+
|
|
140
|
+
% lets the head rule disappear.
|
|
141
|
+
% \renewcommand{\headrulewidth}{0pt}
|
|
142
|
+
% Possible selectors for the optional argument of \fancyhead/\fancyfoot
|
|
143
|
+
% are L (left), C (center) or R (right) for the position of the element
|
|
144
|
+
% and E (even) or O (odd) to distinguish even and odd pages. If you omit
|
|
145
|
+
% E/O the element is set for all pages.
|
|
146
|
+
|
|
147
|
+
% \usepackage{lipsum}
|
|
148
|
+
|
|
149
|
+
% make available command lastpage
|
|
150
|
+
\usepackage{lastpage}
|
|
151
|
+
|
|
152
|
+
% default fontsize 11pt better to add
|
|
153
|
+
% fontsize on the yaml header
|
|
154
|
+
% \usepackage[fontsize=11pt]{scrextend}
|
|
155
|
+
|
|
156
|
+
% comandos para formatar uma tabela
|
|
157
|
+
\usepackage{array}
|
|
158
|
+
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
|
|
159
|
+
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
|
|
160
|
+
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
|
|
161
|
+
|
|
162
|
+
% necessário if we need to import other latex documents
|
|
163
|
+
\usepackage{import}
|
|
164
|
+
|
|
165
|
+
% Command to import an R variable to latex
|
|
166
|
+
\newcommand{\RtoLatex}[2]{\newcommand{#1}{#2}}
|
|
167
|
+
|
|
168
|
+
%
|
|
169
|
+
%\newcommand{\atraso}[1]{\color{red} \textbf {Tempo desde a Assinatura do Contrato: #1 dias}}
|
|
170
|
+
\usepackage{bookmark}
|
|
171
|
+
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
|
|
172
|
+
\urlstyle{same}
|
|
173
|
+
\hypersetup{
|
|
174
|
+
pdftitle={Ruby Plotting with Galaaz},
|
|
175
|
+
pdfauthor={Rodrigo Botafogo},
|
|
176
|
+
hidelinks,
|
|
177
|
+
pdfcreator={LaTeX via pandoc}}
|
|
178
|
+
|
|
179
|
+
\title{Ruby Plotting with Galaaz}
|
|
180
|
+
\usepackage{etoolbox}
|
|
181
|
+
\makeatletter
|
|
182
|
+
\providecommand{\subtitle}[1]{% add subtitle to \maketitle
|
|
183
|
+
\apptocmd{\@title}{\par {\large #1 \par}}{}{}
|
|
184
|
+
}
|
|
185
|
+
\makeatother
|
|
186
|
+
\subtitle{An example of tightly coupling Ruby and R (JRuby + GNU R,
|
|
187
|
+
Galaaz 2.0)}
|
|
188
|
+
\author{Rodrigo Botafogo}
|
|
189
|
+
\date{16 October 2018 (narrative updated for Galaaz 2.0, 2026)}
|
|
190
|
+
|
|
191
|
+
\begin{document}
|
|
192
|
+
\maketitle
|
|
193
|
+
|
|
194
|
+
{
|
|
195
|
+
\setcounter{tocdepth}{2}
|
|
196
|
+
\tableofcontents
|
|
197
|
+
}
|
|
198
|
+
\section{Introduction}\label{introduction}
|
|
199
|
+
|
|
200
|
+
Galaaz is a system for tightly coupling Ruby and R. Ruby is a powerful
|
|
201
|
+
language, with a large community, a very large set of libraries and
|
|
202
|
+
great for web development. However, it lacks libraries for data science,
|
|
203
|
+
statistics, scientific plotting and machine learning. On the other hand,
|
|
204
|
+
R is considered one of the most powerful languages for solving all of
|
|
205
|
+
the above problems. Maybe the strongest competitor to R is Python with
|
|
206
|
+
libraries such as NumPy, Panda, SciPy, SciKit-Learn and a couple more.
|
|
207
|
+
|
|
208
|
+
With Galaaz we do not intend to re-implement any of the scientific
|
|
209
|
+
libraries in R; we allow for very tight coupling between the two
|
|
210
|
+
languages to the point that the Ruby developer does not need to think
|
|
211
|
+
about R syntax for every call. \textbf{Galaaz 2.0} does this with
|
|
212
|
+
\textbf{\href{https://www.jruby.org/}{JRuby}} and \textbf{GNU R}: a
|
|
213
|
+
\textbf{bridge} evaluates R from Ruby and exchanges data between
|
|
214
|
+
processes.
|
|
215
|
+
|
|
216
|
+
An \textbf{earlier} Galaaz prototype used Oracle's \textbf{GraalVM} with
|
|
217
|
+
\textbf{TruffleRuby} and \textbf{FastR} in one JVM. That stack is
|
|
218
|
+
\textbf{historical}; today's documentation and tooling assume
|
|
219
|
+
\textbf{JRuby + GNU R} (see the project manual and
|
|
220
|
+
\textbf{\texttt{bin/galaaz-jruby}} / \textbf{\texttt{bin/gknit}}).
|
|
221
|
+
|
|
222
|
+
For background on the old stack:
|
|
223
|
+
|
|
224
|
+
\begin{itemize}
|
|
225
|
+
\tightlist
|
|
226
|
+
\item
|
|
227
|
+
\href{https://www.graalvm.org/}{GraalVM Home}
|
|
228
|
+
\item
|
|
229
|
+
\href{https://github.com/oracle/truffleruby}{TruffleRuby}
|
|
230
|
+
\item
|
|
231
|
+
\href{https://github.com/oracle/fastr}{FastR}
|
|
232
|
+
\item
|
|
233
|
+
\href{https://medium.com/graalvm/faster-r-with-fastr-4b8db0e0dceb}{Faster
|
|
234
|
+
R with FastR}
|
|
235
|
+
\end{itemize}
|
|
236
|
+
|
|
237
|
+
\subsection{What does Galaaz mean}\label{what-does-galaaz-mean}
|
|
238
|
+
|
|
239
|
+
Galaaz is the Portuguese name for ``Galahad''. From Wikipedia:
|
|
240
|
+
|
|
241
|
+
\begin{verbatim}
|
|
242
|
+
Sir Galahad (sometimes referred to as Galeas or Galath),
|
|
243
|
+
in Arthurian legend, is a knight of King Arthur's Round Table and one
|
|
244
|
+
of the three achievers of the Holy Grail. He is the illegitimate son
|
|
245
|
+
of Sir Lancelot and Elaine of Corbenic, and is renowned for his
|
|
246
|
+
gallantry and purity as the most perfect of all knights. Emerging quite
|
|
247
|
+
late in the medieval Arthurian tradition, Sir Galahad first appears in the
|
|
248
|
+
Lancelot–Grail cycle, and his story is taken up in later works such as
|
|
249
|
+
the Post-Vulgate Cycle and Sir Thomas Malory's Le Morte d'Arthur.
|
|
250
|
+
His name should not be mistaken with Galehaut, a different knight from
|
|
251
|
+
Arthurian legend.
|
|
252
|
+
\end{verbatim}
|
|
253
|
+
|
|
254
|
+
\section{Galaaz Demo}\label{galaaz-demo}
|
|
255
|
+
|
|
256
|
+
\subsection{Prerequisites (Galaaz 2.0)}\label{prerequisites-galaaz-2.0}
|
|
257
|
+
|
|
258
|
+
\begin{itemize}
|
|
259
|
+
\tightlist
|
|
260
|
+
\item
|
|
261
|
+
\textbf{JRuby} and a compatible \textbf{JDK}
|
|
262
|
+
\item
|
|
263
|
+
\textbf{GNU R} on your \texttt{PATH}
|
|
264
|
+
\end{itemize}
|
|
265
|
+
|
|
266
|
+
The following R packages will be automatically installed when necessary,
|
|
267
|
+
but could be installed prior to the demo if desired:
|
|
268
|
+
|
|
269
|
+
\begin{itemize}
|
|
270
|
+
\tightlist
|
|
271
|
+
\item
|
|
272
|
+
ggplot2
|
|
273
|
+
\item
|
|
274
|
+
gridExtra
|
|
275
|
+
\end{itemize}
|
|
276
|
+
|
|
277
|
+
Installation of R packages requires a development environment. In Linux,
|
|
278
|
+
the gnu compiler and tools should be enough. I am not sure what is
|
|
279
|
+
needed on the Mac.
|
|
280
|
+
|
|
281
|
+
In order to run the `specs' the following Ruby package is necessary:
|
|
282
|
+
|
|
283
|
+
\begin{itemize}
|
|
284
|
+
\tightlist
|
|
285
|
+
\item
|
|
286
|
+
gem install rspec
|
|
287
|
+
\end{itemize}
|
|
288
|
+
|
|
289
|
+
\subsection{Preparation}\label{preparation}
|
|
290
|
+
|
|
291
|
+
\begin{itemize}
|
|
292
|
+
\tightlist
|
|
293
|
+
\item
|
|
294
|
+
gem install galaaz
|
|
295
|
+
\end{itemize}
|
|
296
|
+
|
|
297
|
+
\subsection{Running the demo}\label{running-the-demo}
|
|
298
|
+
|
|
299
|
+
The ggplot for this demos was extracted from:
|
|
300
|
+
\url{http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html}.
|
|
301
|
+
|
|
302
|
+
On the console do
|
|
303
|
+
|
|
304
|
+
\begin{verbatim}
|
|
305
|
+
> galaaz master_list:scatter_plot
|
|
306
|
+
\end{verbatim}
|
|
307
|
+
|
|
308
|
+
\subsection{Running other demos}\label{running-other-demos}
|
|
309
|
+
|
|
310
|
+
Doing on the console
|
|
311
|
+
|
|
312
|
+
\begin{verbatim}
|
|
313
|
+
> galaaz -T
|
|
314
|
+
\end{verbatim}
|
|
315
|
+
|
|
316
|
+
will show a list with all available demos. To run any of the demos in
|
|
317
|
+
the list, substitute the call to `rake' to `galaaz'. For instance, one
|
|
318
|
+
of the examples in the list is `rake sthda:bar'. In order to run this
|
|
319
|
+
example just do `galaaz sthda:bar'. Doing `galaaz sthda:all' will run
|
|
320
|
+
all demos in the sthda cathegory. Some of the examples require `rspec'
|
|
321
|
+
do be available. To install `rspec' just do `gem install rspec'.
|
|
322
|
+
|
|
323
|
+
\section{The demo code}\label{the-demo-code}
|
|
324
|
+
|
|
325
|
+
The following is the Ruby code and plot for the above example. There is
|
|
326
|
+
a small difference between the code in the example and the code bellow.
|
|
327
|
+
If the example is ran, the plot will appear on the screen, bellow, we
|
|
328
|
+
generate an `svg' image and then include it in this document. In order
|
|
329
|
+
to generate and image, the R.svg device is used. To generate the plot on
|
|
330
|
+
the screen, use the R.awt device, as commented on the code.
|
|
331
|
+
|
|
332
|
+
\begin{Shaded}
|
|
333
|
+
\begin{Highlighting}[]
|
|
334
|
+
\FunctionTok{require} \VerbatimStringTok{\textquotesingle{}galaaz\textquotesingle{}}
|
|
335
|
+
\FunctionTok{require} \VerbatimStringTok{\textquotesingle{}ggplot\textquotesingle{}}
|
|
336
|
+
|
|
337
|
+
\CommentTok{\# load package and data}
|
|
338
|
+
\ConstantTok{R}\AttributeTok{.options}\NormalTok{(}\WarningTok{scipen:} \DecValTok{999}\NormalTok{) }\CommentTok{\# turn{-}off scientific notation like 1e+48}
|
|
339
|
+
\ConstantTok{R}\AttributeTok{.theme\_set}\NormalTok{(}\ConstantTok{R}\AttributeTok{.theme\_bw}\NormalTok{) }\CommentTok{\# pre{-}set the bw theme.}
|
|
340
|
+
|
|
341
|
+
\NormalTok{midwest }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\WarningTok{:midwest}
|
|
342
|
+
|
|
343
|
+
\CommentTok{\# Scatterplot}
|
|
344
|
+
\NormalTok{gg }\OperatorTok{=}\NormalTok{ midwest}\AttributeTok{.ggplot}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{x:} \WarningTok{:area}\NormalTok{, }\WarningTok{y:} \WarningTok{:poptotal}\NormalTok{)) }\OperatorTok{+}
|
|
345
|
+
\ConstantTok{R}\AttributeTok{.geom\_point}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{col:} \WarningTok{:state}\NormalTok{, }\WarningTok{size:} \WarningTok{:popdensity}\NormalTok{)) }\OperatorTok{+}
|
|
346
|
+
\ConstantTok{R}\AttributeTok{.geom\_smooth}\NormalTok{(}\WarningTok{method:} \StringTok{"loess"}\NormalTok{, }\WarningTok{se:} \DecValTok{false}\NormalTok{) }\OperatorTok{+}
|
|
347
|
+
\ConstantTok{R}\AttributeTok{.xlim}\NormalTok{(}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{0}\NormalTok{, }\FloatTok{0.1}\NormalTok{)) }\OperatorTok{+}
|
|
348
|
+
\ConstantTok{R}\AttributeTok{.ylim}\NormalTok{(}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{0}\NormalTok{, }\DecValTok{500000}\NormalTok{)) }\OperatorTok{+}
|
|
349
|
+
\ConstantTok{R}\AttributeTok{.labs}\NormalTok{(}\WarningTok{subtitle:} \StringTok{"Area Vs Population"}\NormalTok{, }
|
|
350
|
+
\WarningTok{y:} \StringTok{"Population"}\NormalTok{, }
|
|
351
|
+
\WarningTok{x:} \StringTok{"Area"}\NormalTok{, }
|
|
352
|
+
\WarningTok{title:} \StringTok{"Scatterplot"}\NormalTok{, }
|
|
353
|
+
\WarningTok{caption:} \StringTok{"Source: midwest"}\NormalTok{)}
|
|
354
|
+
|
|
355
|
+
\FunctionTok{puts}\NormalTok{ gg}
|
|
356
|
+
\end{Highlighting}
|
|
357
|
+
\end{Shaded}
|
|
358
|
+
|
|
359
|
+
\pandocbounded{\includegraphics[keepaspectratio]{galaaz_ggplot_files/figure-latex/midwest_rb.pdf}}
|
|
360
|
+
|
|
361
|
+
In R, the code to generate this plot is the following
|
|
362
|
+
|
|
363
|
+
\begin{Shaded}
|
|
364
|
+
\begin{Highlighting}[]
|
|
365
|
+
\CommentTok{\# install.packages("ggplot2")}
|
|
366
|
+
\CommentTok{\# load package and data}
|
|
367
|
+
\FunctionTok{options}\NormalTok{(}\AttributeTok{scipen=}\DecValTok{999}\NormalTok{) }\CommentTok{\# turn{-}off scientific notation like 1e+48}
|
|
368
|
+
\FunctionTok{library}\NormalTok{(ggplot2)}
|
|
369
|
+
\FunctionTok{theme\_set}\NormalTok{(}\FunctionTok{theme\_bw}\NormalTok{()) }\CommentTok{\# pre{-}set the bw theme.}
|
|
370
|
+
\FunctionTok{data}\NormalTok{(}\StringTok{"midwest"}\NormalTok{, }\AttributeTok{package =} \StringTok{"ggplot2"}\NormalTok{)}
|
|
371
|
+
\CommentTok{\# midwest \textless{}{-} read.csv("http://goo.gl/G1K41K") \# bkup data source}
|
|
372
|
+
|
|
373
|
+
\CommentTok{\# Scatterplot}
|
|
374
|
+
\NormalTok{gg }\OtherTok{\textless{}{-}} \FunctionTok{ggplot}\NormalTok{(midwest, }\FunctionTok{aes}\NormalTok{(}\AttributeTok{x=}\NormalTok{area, }\AttributeTok{y=}\NormalTok{poptotal)) }\SpecialCharTok{+}
|
|
375
|
+
\FunctionTok{geom\_point}\NormalTok{(}\FunctionTok{aes}\NormalTok{(}\AttributeTok{col=}\NormalTok{state, }\AttributeTok{size=}\NormalTok{popdensity)) }\SpecialCharTok{+}
|
|
376
|
+
\FunctionTok{geom\_smooth}\NormalTok{(}\AttributeTok{method=}\StringTok{"loess"}\NormalTok{, }\AttributeTok{se=}\NormalTok{F) }\SpecialCharTok{+}
|
|
377
|
+
\FunctionTok{xlim}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{, }\FloatTok{0.1}\NormalTok{)) }\SpecialCharTok{+}
|
|
378
|
+
\FunctionTok{ylim}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{, }\DecValTok{500000}\NormalTok{)) }\SpecialCharTok{+}
|
|
379
|
+
\FunctionTok{labs}\NormalTok{(}\AttributeTok{subtitle=}\StringTok{"Area Vs Population"}\NormalTok{, }
|
|
380
|
+
\AttributeTok{y=}\StringTok{"Population"}\NormalTok{, }
|
|
381
|
+
\AttributeTok{x=}\StringTok{"Area"}\NormalTok{, }
|
|
382
|
+
\AttributeTok{title=}\StringTok{"Scatterplot"}\NormalTok{, }
|
|
383
|
+
\AttributeTok{caption =} \StringTok{"Source: midwest"}\NormalTok{)}
|
|
384
|
+
|
|
385
|
+
\FunctionTok{plot}\NormalTok{(gg)}
|
|
386
|
+
\end{Highlighting}
|
|
387
|
+
\end{Shaded}
|
|
388
|
+
|
|
389
|
+
Note that both codes are very similar. The Ruby code requires the use of
|
|
390
|
+
``R.'' before calling any functions, for instance R function
|
|
391
|
+
`geom\_point' becomes `R.geom\_point' in Ruby. R named parameters such
|
|
392
|
+
as (col = state, size = popdensity), become in Ruby (col: :state, size:
|
|
393
|
+
:popdensity).
|
|
394
|
+
|
|
395
|
+
One last point that needs to be observed is the call to the `aes'
|
|
396
|
+
function. In Ruby instead of doing `R.aes', we use `E.aes'. The
|
|
397
|
+
explanation of why E.aes is needed is an advanced topic in R and depends
|
|
398
|
+
on what is know as Non-standard Evaluation (NSE) in R. In short,
|
|
399
|
+
function `aes' is lazily evaluated in R, i.e., in R when calling
|
|
400
|
+
geom\_point(aes(col=state, size=popdensity)), function geom\_point
|
|
401
|
+
receives as argument something similar to a string containing
|
|
402
|
+
`aes(col=state, size=popdensity)', and the aes function will be
|
|
403
|
+
evaluated inside the geom\_point function. In Ruby, there is no Lazy
|
|
404
|
+
evaluation and doing R.aes would try to evaluate aes immediately. In
|
|
405
|
+
order to delay the evaluation of function aes we need to use E.aes. The
|
|
406
|
+
interested reader on NSE in R is directed to
|
|
407
|
+
\url{http://adv-r.had.co.nz/Computing-on-the-language.html}.
|
|
408
|
+
|
|
409
|
+
\section{An extension to the example}\label{an-extension-to-the-example}
|
|
410
|
+
|
|
411
|
+
If both codes are so similar, then why would one use Ruby instead of R
|
|
412
|
+
and what good is galaaz after all?
|
|
413
|
+
|
|
414
|
+
Ruby is a modern OO language with numerous very useful constructs such
|
|
415
|
+
as classes, modules, blocks, procs, etc. The example above focus on the
|
|
416
|
+
coupling of both languages, and does not show the use of other Ruby
|
|
417
|
+
constructs. In the following example, we will show a more complex
|
|
418
|
+
example using other Ruby constructs. This is certainly not a very well
|
|
419
|
+
written and robust Ruby code, but it give the idea of how Ruby and R are
|
|
420
|
+
strongly coupled.
|
|
421
|
+
|
|
422
|
+
Let's imagine that we work in a corporation that has its plot themes.
|
|
423
|
+
So, it has defined a `CorpTheme' module. Plots in this corporation
|
|
424
|
+
should not have grids, numbers in labels should not use scientific
|
|
425
|
+
notation and the preferred color is blue.
|
|
426
|
+
|
|
427
|
+
\begin{Shaded}
|
|
428
|
+
\begin{Highlighting}[]
|
|
429
|
+
\CommentTok{\# corp\_theme.rb}
|
|
430
|
+
\CommentTok{\# defines the corporate theme for all plots}
|
|
431
|
+
|
|
432
|
+
\ControlFlowTok{module} \DataTypeTok{CorpTheme}
|
|
433
|
+
|
|
434
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
435
|
+
\CommentTok{\# Defines the plot theme (visualization). In this theme we remove major and minor}
|
|
436
|
+
\CommentTok{\# grids, borders and background. We also turn{-}off scientific notation.}
|
|
437
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
438
|
+
|
|
439
|
+
\ControlFlowTok{def} \DecValTok{self}\AttributeTok{.global\_theme}
|
|
440
|
+
|
|
441
|
+
\ConstantTok{R}\AttributeTok{.options}\NormalTok{(}\WarningTok{scipen:} \DecValTok{999}\NormalTok{) }\CommentTok{\# turn{-}off scientific notation like 1e+48}
|
|
442
|
+
|
|
443
|
+
\CommentTok{\# remove major grids}
|
|
444
|
+
\NormalTok{ global\_theme }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{panel\_\_grid\_\_major:} \ConstantTok{E}\AttributeTok{.element\_blank}\NormalTok{())}
|
|
445
|
+
\CommentTok{\# remove minor grids}
|
|
446
|
+
\NormalTok{ global\_theme }\OperatorTok{=}\NormalTok{ global\_theme }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{panel\_\_grid\_\_minor:} \ConstantTok{E}\AttributeTok{.element\_blank}\NormalTok{)}
|
|
447
|
+
\CommentTok{\# remove border}
|
|
448
|
+
\NormalTok{ global\_theme }\OperatorTok{=}\NormalTok{ global\_theme }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{panel\_\_border:} \ConstantTok{E}\AttributeTok{.element\_blank}\NormalTok{)}
|
|
449
|
+
\CommentTok{\# remove background}
|
|
450
|
+
\NormalTok{ global\_theme }\OperatorTok{=}\NormalTok{ global\_theme }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{panel\_\_background:} \ConstantTok{E}\AttributeTok{.element\_blank}\NormalTok{)}
|
|
451
|
+
\CommentTok{\# Change axis font}
|
|
452
|
+
\NormalTok{ global\_theme }\OperatorTok{=}\NormalTok{ global\_theme }\OperatorTok{+}
|
|
453
|
+
\ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{axis\_\_text:} \ConstantTok{E}\AttributeTok{.element\_text}\NormalTok{(}\WarningTok{size:} \DecValTok{8}\NormalTok{, }\WarningTok{color:} \StringTok{"\#000080"}\NormalTok{))}
|
|
454
|
+
\CommentTok{\# change color of axis titles}
|
|
455
|
+
\NormalTok{ global\_theme }\OperatorTok{=}\NormalTok{ global\_theme }\OperatorTok{+}
|
|
456
|
+
\ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{axis\_\_title:} \ConstantTok{E}\AttributeTok{.element\_text}\NormalTok{(}
|
|
457
|
+
\WarningTok{color:} \StringTok{"\#000080"}\NormalTok{, }
|
|
458
|
+
\WarningTok{face:} \StringTok{"bold"}\NormalTok{,}
|
|
459
|
+
\WarningTok{size:} \DecValTok{8}\NormalTok{,}
|
|
460
|
+
\WarningTok{hjust:} \DecValTok{1}\NormalTok{))}
|
|
461
|
+
\ControlFlowTok{end}
|
|
462
|
+
|
|
463
|
+
\ControlFlowTok{end}
|
|
464
|
+
\end{Highlighting}
|
|
465
|
+
\end{Shaded}
|
|
466
|
+
|
|
467
|
+
We now define a ScatterPlot class:
|
|
468
|
+
|
|
469
|
+
\begin{Shaded}
|
|
470
|
+
\begin{Highlighting}[]
|
|
471
|
+
\CommentTok{\# ScatterPlot.rb}
|
|
472
|
+
\CommentTok{\# creates a scatter plot and allow some configuration}
|
|
473
|
+
|
|
474
|
+
\ControlFlowTok{class} \DataTypeTok{ScatterPlot}
|
|
475
|
+
|
|
476
|
+
\OtherTok{attr\_accessor} \WarningTok{:title}
|
|
477
|
+
\OtherTok{attr\_accessor} \WarningTok{:subtitle}
|
|
478
|
+
\OtherTok{attr\_accessor} \WarningTok{:caption}
|
|
479
|
+
\OtherTok{attr\_accessor} \WarningTok{:x\_label}
|
|
480
|
+
\OtherTok{attr\_accessor} \WarningTok{:y\_label}
|
|
481
|
+
|
|
482
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
483
|
+
\CommentTok{\# Initialize the plot with the data and the x and y variables}
|
|
484
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
485
|
+
|
|
486
|
+
\ControlFlowTok{def}\NormalTok{ initialize(data, x}\OperatorTok{:}\NormalTok{, }\WarningTok{y:}\NormalTok{)}
|
|
487
|
+
\OtherTok{@data} \OperatorTok{=}\NormalTok{ data}
|
|
488
|
+
\OtherTok{@x} \OperatorTok{=}\NormalTok{ x}
|
|
489
|
+
\OtherTok{@y} \OperatorTok{=}\NormalTok{ y}
|
|
490
|
+
\ControlFlowTok{end}
|
|
491
|
+
|
|
492
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
493
|
+
\CommentTok{\# Define groupings by color and size}
|
|
494
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
495
|
+
|
|
496
|
+
\ControlFlowTok{def}\NormalTok{ group\_by(color}\OperatorTok{:}\NormalTok{, }\WarningTok{size:}\NormalTok{)}
|
|
497
|
+
\OtherTok{@color\_by} \OperatorTok{=}\NormalTok{ color}
|
|
498
|
+
\OtherTok{@size\_by} \OperatorTok{=}\NormalTok{ size}
|
|
499
|
+
\ControlFlowTok{end}
|
|
500
|
+
|
|
501
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
502
|
+
\CommentTok{\# Add a smoothing line, and if confidence is true the add a confidence interval, if}
|
|
503
|
+
\CommentTok{\# false does not add the confidence interval}
|
|
504
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
505
|
+
|
|
506
|
+
\ControlFlowTok{def}\NormalTok{ add\_smoothing\_line(method}\OperatorTok{:}\NormalTok{, }\WarningTok{confidence:} \DecValTok{true}\NormalTok{)}
|
|
507
|
+
\OtherTok{@method} \OperatorTok{=}\NormalTok{ method}
|
|
508
|
+
\OtherTok{@confidence} \OperatorTok{=}\NormalTok{ confidence}
|
|
509
|
+
\ControlFlowTok{end}
|
|
510
|
+
|
|
511
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
512
|
+
\CommentTok{\# Creates the graph title, properly formated for this theme}
|
|
513
|
+
\CommentTok{\# @param title [String] The title to add to the graph}
|
|
514
|
+
\CommentTok{\# @return textGrob that can be included in a graph}
|
|
515
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
516
|
+
|
|
517
|
+
\ControlFlowTok{def}\NormalTok{ graph\_params(title}\OperatorTok{:} \StringTok{""}\NormalTok{, }\WarningTok{subtitle:} \StringTok{""}\NormalTok{, }\WarningTok{caption:} \StringTok{""}\NormalTok{, }\WarningTok{x\_label:} \StringTok{""}\NormalTok{, }\WarningTok{y\_label:} \StringTok{""}\NormalTok{)}
|
|
518
|
+
\ConstantTok{R}\AttributeTok{.labs}\NormalTok{(}
|
|
519
|
+
\WarningTok{title:}\NormalTok{ title, }
|
|
520
|
+
\WarningTok{subtitle:}\NormalTok{ subtitle, }
|
|
521
|
+
\WarningTok{caption:}\NormalTok{ caption,}
|
|
522
|
+
\WarningTok{y\_label:}\NormalTok{ y\_label, }
|
|
523
|
+
\WarningTok{x\_label:}\NormalTok{ x\_label, }
|
|
524
|
+
\NormalTok{ )}
|
|
525
|
+
\ControlFlowTok{end}
|
|
526
|
+
|
|
527
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
528
|
+
\CommentTok{\# Prepare the plot\textquotesingle{}s points}
|
|
529
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
530
|
+
|
|
531
|
+
\ControlFlowTok{def}\NormalTok{ points}
|
|
532
|
+
\NormalTok{ params }\OperatorTok{=} \OperatorTok{\{\}}
|
|
533
|
+
\NormalTok{ params}\KeywordTok{[}\WarningTok{:col}\KeywordTok{]} \OperatorTok{=} \OtherTok{@color\_by} \ControlFlowTok{if} \OtherTok{@color\_by}
|
|
534
|
+
\NormalTok{ params}\KeywordTok{[}\WarningTok{:size}\KeywordTok{]} \OperatorTok{=} \OtherTok{@size\_by} \ControlFlowTok{if} \OtherTok{@size\_by}
|
|
535
|
+
\ConstantTok{R}\AttributeTok{.geom\_point}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(params))}
|
|
536
|
+
\ControlFlowTok{end}
|
|
537
|
+
|
|
538
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
539
|
+
\CommentTok{\# Plots the scatterplot}
|
|
540
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
541
|
+
|
|
542
|
+
\ControlFlowTok{def}\NormalTok{ plot}
|
|
543
|
+
\NormalTok{ gg }\OperatorTok{=} \OtherTok{@data}\AttributeTok{.ggplot}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{x:} \OtherTok{@x}\NormalTok{, }\WarningTok{y:} \OtherTok{@y}\NormalTok{)) }\OperatorTok{+}
|
|
544
|
+
\NormalTok{ points }\OperatorTok{+}
|
|
545
|
+
\ConstantTok{R}\AttributeTok{.geom\_smooth}\NormalTok{(}\WarningTok{method:} \OtherTok{@method}\NormalTok{, }\WarningTok{se:} \OtherTok{@confidence}\NormalTok{) }\OperatorTok{+}
|
|
546
|
+
\ConstantTok{R}\AttributeTok{.xlim}\NormalTok{(}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{0}\NormalTok{, }\FloatTok{0.1}\NormalTok{)) }\OperatorTok{+}
|
|
547
|
+
\ConstantTok{R}\AttributeTok{.ylim}\NormalTok{(}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{0}\NormalTok{, }\DecValTok{500000}\NormalTok{)) }\OperatorTok{+}
|
|
548
|
+
\NormalTok{ graph\_params(}\WarningTok{title:} \OtherTok{@title}\NormalTok{,}
|
|
549
|
+
\WarningTok{subtitle:} \OtherTok{@subtitle}\NormalTok{, }
|
|
550
|
+
\WarningTok{y\_label:} \OtherTok{@y\_label}\NormalTok{, }
|
|
551
|
+
\WarningTok{x\_label:} \OtherTok{@x\_label}\NormalTok{, }
|
|
552
|
+
\WarningTok{caption:} \OtherTok{@caption}\NormalTok{) }\OperatorTok{+}
|
|
553
|
+
\DataTypeTok{CorpTheme}\AttributeTok{.global\_theme}
|
|
554
|
+
|
|
555
|
+
\FunctionTok{puts}\NormalTok{ gg}
|
|
556
|
+
|
|
557
|
+
\ControlFlowTok{end}
|
|
558
|
+
|
|
559
|
+
\ControlFlowTok{end}
|
|
560
|
+
\end{Highlighting}
|
|
561
|
+
\end{Shaded}
|
|
562
|
+
|
|
563
|
+
And this is the final code for making the scatter plot with the midwest
|
|
564
|
+
data
|
|
565
|
+
|
|
566
|
+
\begin{Shaded}
|
|
567
|
+
\begin{Highlighting}[]
|
|
568
|
+
\FunctionTok{require} \VerbatimStringTok{\textquotesingle{}galaaz\textquotesingle{}}
|
|
569
|
+
\FunctionTok{require} \VerbatimStringTok{\textquotesingle{}ggplot\textquotesingle{}}
|
|
570
|
+
|
|
571
|
+
\NormalTok{sp }\OperatorTok{=} \DataTypeTok{ScatterPlot}\AttributeTok{.new}\NormalTok{(}\OperatorTok{\textasciitilde{}}\WarningTok{:midwest}\NormalTok{, }\WarningTok{x:} \WarningTok{:area}\NormalTok{, }\WarningTok{y:} \WarningTok{:poptotal}\NormalTok{)}
|
|
572
|
+
\NormalTok{sp}\AttributeTok{.title} \OperatorTok{=} \StringTok{"Midwest Dataset {-} Scatterplot"}
|
|
573
|
+
\NormalTok{sp}\AttributeTok{.subtitle} \OperatorTok{=} \StringTok{"Area Vs Population"}
|
|
574
|
+
\NormalTok{sp}\AttributeTok{.caption} \OperatorTok{=} \StringTok{"Source: midwest"}
|
|
575
|
+
\NormalTok{sp}\AttributeTok{.x\_label} \OperatorTok{=} \StringTok{"Area"}
|
|
576
|
+
\NormalTok{sp}\AttributeTok{.y\_label} \OperatorTok{=} \StringTok{"Population"}
|
|
577
|
+
\NormalTok{sp}\AttributeTok{.group\_by}\NormalTok{(}\WarningTok{color:} \WarningTok{:state}\NormalTok{, }\WarningTok{size:} \WarningTok{:popdensity}\NormalTok{) }\CommentTok{\# try sp.group\_by(color: :state)}
|
|
578
|
+
\CommentTok{\# available methods: "lm", "glm", "loess", "gam"}
|
|
579
|
+
\NormalTok{sp}\AttributeTok{.add\_smoothing\_line}\NormalTok{(}\WarningTok{method:} \StringTok{"glm"}\NormalTok{) }
|
|
580
|
+
\NormalTok{sp}\AttributeTok{.plot}
|
|
581
|
+
\end{Highlighting}
|
|
582
|
+
\end{Shaded}
|
|
583
|
+
|
|
584
|
+
\pandocbounded{\includegraphics[keepaspectratio]{galaaz_ggplot_files/figure-latex/scatter_plot_rb.pdf}}
|
|
585
|
+
|
|
586
|
+
\section{Conclusion}\label{conclusion}
|
|
587
|
+
|
|
588
|
+
R is a very powerful language for statistical analysis, data analytics,
|
|
589
|
+
machine learning, plotting and many other scientific applications with a
|
|
590
|
+
very large package ecosystem. However R is often considered hard to
|
|
591
|
+
learn and lacking modern computer languages constructs such as object
|
|
592
|
+
oriented classes, modules, lambdas, etc. For this reason, many
|
|
593
|
+
developers have started or switched from R to Python.
|
|
594
|
+
|
|
595
|
+
With Galaaz, R programmers can almost transparently migrate from R to
|
|
596
|
+
Ruby, since syntax is almost identical and \textbf{GNU R} remains the
|
|
597
|
+
engine for statistics and \textbf{ggplot2}. Further, by using Galaaz the
|
|
598
|
+
R developer can start (slowly if needed) using Ruby's constructs and
|
|
599
|
+
libraries that nicely complement R packages.
|
|
600
|
+
|
|
601
|
+
For the Ruby developer, Galaaz allows the immediate use of R functions
|
|
602
|
+
with minimal ceremony. As shown in the second example above, class
|
|
603
|
+
\texttt{ScatterPlot} hides most R call details from the Ruby developer.
|
|
604
|
+
\textbf{JRuby} provides \textbf{real parallel threads} on the Ruby side
|
|
605
|
+
and access to the JVM ecosystem when you need it.
|
|
606
|
+
|
|
607
|
+
\end{document}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The following is the Ruby code and plot for the above example. There is a small difference between
|
|
2
|
-
the code in the example and the code
|
|
3
|
-
screen
|
|
2
|
+
the code in the example and the code below. If the example is **run**, the plot will appear on the
|
|
3
|
+
screen; below, we generate an SVG image and then include it in this document. In order to
|
|
4
4
|
generate and image, the R.svg device is used. To generate the plot on the screen, use the R.awt
|
|
5
5
|
device, as commented on the code.
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@ require 'ggplot'
|
|
|
12
12
|
R.options(scipen: 999) # turn-off scientific notation like 1e+48
|
|
13
13
|
R.theme_set(R.theme_bw) # pre-set the bw theme.
|
|
14
14
|
|
|
15
|
-
midwest =
|
|
15
|
+
midwest = ~R[:midwest]
|
|
16
16
|
|
|
17
17
|
# Scatterplot
|
|
18
18
|
gg = midwest.ggplot(E.aes(x: :area, y: :poptotal)) +
|
|
File without changes
|