galaaz 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +696 -270
- data/Rakefile +9 -22
- data/bin/gknit +2 -217
- data/bin/gknit_old_r +236 -0
- data/bin/grun +5 -0
- data/blogs/dev/dev.Rmd +7 -0
- data/blogs/dev/dev.html +34 -26
- data/blogs/dev/dev.md +40 -25
- data/blogs/dev/dev_files/figure-html/bubble-1.png +0 -0
- data/blogs/dev/dev_files/figure-html/diverging_bar. +0 -0
- data/blogs/dev/dev_files/figure-html/diverging_bar.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +4 -4
- data/blogs/galaaz_ggplot/galaaz_ggplot.html +251 -59
- data/blogs/galaaz_ggplot/galaaz_ggplot.log +640 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.md +199 -95
- data/blogs/galaaz_ggplot/galaaz_ggplot.tex +45 -228
- data/blogs/galaaz_ggplot/midwest.png +0 -0
- data/blogs/galaaz_ggplot/scatter_plot.png +0 -0
- data/blogs/gknit/gknit.Rmd +271 -148
- data/blogs/manual/manual.Rmd +212 -0
- data/blogs/manual/manual.html +1832 -0
- data/blogs/manual/manual.md +751 -0
- data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
- data/blogs/ruby_plot/ruby_plot.Rmd +5 -69
- data/blogs/ruby_plot/ruby_plot.html +195 -236
- data/blogs/ruby_plot/ruby_plot.md +1 -261
- data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.svg +38 -38
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_dotplot.rb +5 -5
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_jitter.rb +1 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_violin.rb +3 -7
- data/examples/sthda_ggplot/two_variables_error/geom_crossbar.rb +3 -1
- data/lib/R_interface/r.rb +12 -9
- data/lib/R_interface/r_methods.rb +2 -2
- data/lib/R_interface/rbinary_operators.rb +2 -20
- data/lib/R_interface/rdata_frame.rb +56 -9
- data/lib/R_interface/rdevices.R +0 -12
- data/lib/R_interface/rexpression.rb +0 -97
- data/lib/R_interface/rindexed_object.rb +12 -3
- data/lib/R_interface/rlanguage.rb +1 -1
- data/lib/R_interface/rlist.rb +29 -4
- data/lib/R_interface/rlogical_operators.rb +50 -0
- data/lib/R_interface/rmatrix.rb +7 -1
- data/lib/R_interface/robject.rb +29 -15
- data/lib/R_interface/rsupport.rb +74 -58
- data/lib/R_interface/rsymbol.rb +2 -1
- data/lib/R_interface/ruby_extensions.rb +11 -2
- data/lib/R_interface/rvector.rb +26 -11
- data/lib/gknit.rb +2 -0
- data/lib/gknit/include_engine.rb +57 -0
- data/lib/gknit/knitr_engine.rb +596 -50
- data/lib/gknit/rb_engine.rb +56 -0
- data/lib/gknit/ruby_engine.rb +13 -36
- data/lib/util/exec_ruby.rb +132 -21
- data/lib/util/inline_file.rb +9 -7
- data/specs/all.rb +5 -0
- data/specs/figures/bg.jpeg +0 -0
- data/specs/figures/bg.png +0 -0
- data/specs/figures/bg.svg +57 -0
- data/specs/figures/no_args.jpeg +0 -0
- data/specs/figures/no_args.png +0 -0
- data/specs/figures/no_args.svg +57 -0
- 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/r_dataframe.spec.rb +29 -27
- data/specs/r_devices.spec.rb +347 -0
- data/specs/r_eval.spec.rb +10 -3
- data/specs/r_formula.spec.rb +2 -2
- data/specs/r_language.spec.rb +112 -0
- data/specs/r_list.spec.rb +174 -14
- data/specs/r_list_apply.spec.rb +17 -10
- data/specs/r_matrix.spec.rb +3 -3
- data/specs/r_vector_operators.spec.rb +13 -7
- data/specs/tmp.rb +42 -12
- data/version.rb +1 -1
- metadata +28 -24
- data/bin/gknit2 +0 -14
- data/bin/prepareR.rb +0 -3
- data/bin/tmp.py +0 -51
- data/blogs/gknit/gknit.html +0 -528
- data/blogs/gknit/gknit.md +0 -628
- data/blogs/gknit/gknit.pdf +0 -0
- data/blogs/gknit/gknit.tex +0 -745
- 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/ruby_plot/figures/dose_len.png +0 -0
- data/blogs/ruby_plot/figures/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/figures/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/figures/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/figures/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/figures/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/figures/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/figures/facets_with_points.png +0 -0
- data/blogs/ruby_plot/figures/final_box_plot.png +0 -0
- data/blogs/ruby_plot/figures/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/figures/violin_with_jitter.png +0 -0
- data/lib/R/eng_ruby.R +0 -62
- data/lib/R_interface/rdevices.rb +0 -225
@@ -143,24 +143,6 @@ following chunk that 'ToothGrowth' is the R variable and Ruby's '@tooth_growth'
|
|
143
143
|
assigned the value of '~:ToothGrowth'.
|
144
144
|
|
145
145
|
|
146
|
-
```ruby
|
147
|
-
# Read the R ToothGrowth variable and assign it to the
|
148
|
-
# Ruby instance variable @tooth_growth that will be
|
149
|
-
# available to all Ruby chunks in this document.
|
150
|
-
@tooth_growth = ~:ToothGrowth
|
151
|
-
# print the first few elements of the dataset
|
152
|
-
puts @tooth_growth.head
|
153
|
-
```
|
154
|
-
|
155
|
-
```
|
156
|
-
## len supp dose
|
157
|
-
## 1 4.2 VC 0.5
|
158
|
-
## 2 11.5 VC 0.5
|
159
|
-
## 3 7.3 VC 0.5
|
160
|
-
## 4 5.8 VC 0.5
|
161
|
-
## 5 6.4 VC 0.5
|
162
|
-
## 6 10.0 VC 0.5
|
163
|
-
```
|
164
146
|
|
165
147
|
Great! We've managed to read the ToothGrowth dataset and take a look at its elements.
|
166
148
|
We see here the first 6 rows of the dataset. To access a column, follow the dataset name
|
@@ -168,15 +150,6 @@ with a dot ('.') and the name of the column. Also use dot notation to chain meth
|
|
168
150
|
in usual Ruby style.
|
169
151
|
|
170
152
|
|
171
|
-
```ruby
|
172
|
-
# Access the tooth_growth 'len' column and print the first few
|
173
|
-
# elements of this column with the 'head' method.
|
174
|
-
puts @tooth_growth.len.head
|
175
|
-
```
|
176
|
-
|
177
|
-
```
|
178
|
-
## [1] 4.2 11.5 7.3 5.8 6.4 10.0
|
179
|
-
```
|
180
153
|
|
181
154
|
The 'dose' column contains a numeric value with either, 0.5, 1 or 2, although the
|
182
155
|
first 6 rows as seen above only contain the 0.5 values. Even though those are
|
@@ -186,22 +159,11 @@ function from Galaaz the dot ('.') in the function name is substituted by '__' (
|
|
186
159
|
The function 'as.factor' becomes 'R.as__factor' or just 'as__factor' when chaining.
|
187
160
|
|
188
161
|
|
189
|
-
```ruby
|
190
|
-
# convert the dose to a factor
|
191
|
-
@tooth_growth.dose = @tooth_growth.dose.as__factor
|
192
|
-
```
|
193
162
|
|
194
163
|
Let's explore some more details of this dataset. In particular, let's look at its dimensions,
|
195
164
|
structure and summary statistics.
|
196
165
|
|
197
166
|
|
198
|
-
```ruby
|
199
|
-
puts @tooth_growth.dim
|
200
|
-
```
|
201
|
-
|
202
|
-
```
|
203
|
-
## [1] 60 3
|
204
|
-
```
|
205
167
|
|
206
168
|
This dataset has 60 rows, one for each subject and 3 columns, as we have already seen.
|
207
169
|
|
@@ -210,35 +172,12 @@ functions does not return anything and prints the structure of the dataset
|
|
210
172
|
as a side effect.
|
211
173
|
|
212
174
|
|
213
|
-
```ruby
|
214
|
-
@tooth_growth.str
|
215
|
-
```
|
216
|
-
|
217
|
-
```
|
218
|
-
## 'data.frame': 60 obs. of 3 variables:
|
219
|
-
## $ len : num 4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ...
|
220
|
-
## $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
|
221
|
-
## $ dose: Factor w/ 3 levels "0.5","1","2": 1 1 1 1 1 1 1 1 1 1 ...
|
222
|
-
```
|
223
175
|
Observe that both variables 'supp' and 'dose' are factors. The system made variable 'supp'
|
224
176
|
a factor automatically, since it contais two strings OJ and VC.
|
225
177
|
|
226
178
|
Finally, using the summary method, we get the statistical summary for the dataset
|
227
179
|
|
228
180
|
|
229
|
-
```ruby
|
230
|
-
puts @tooth_growth.summary
|
231
|
-
```
|
232
|
-
|
233
|
-
```
|
234
|
-
## len supp dose
|
235
|
-
## Min. : 4.20 OJ:30 0.5:20
|
236
|
-
## 1st Qu.:13.07 VC:30 1 :20
|
237
|
-
## Median :19.25 2 :20
|
238
|
-
## Mean :18.81
|
239
|
-
## 3rd Qu.:25.27
|
240
|
-
## Max. :33.90
|
241
|
-
```
|
242
181
|
|
243
182
|
# Doing the Data Analysis
|
244
183
|
|
@@ -274,23 +213,12 @@ image gets a default name of 'Rplot\<nnn\>' where \<nnn\> is the number of the p
|
|
274
213
|
closes the device and creates the 'png' file. We can
|
275
214
|
then include the generated 'png' file in the document by adding an rmarkdown directive.
|
276
215
|
|
277
|
-
|
278
|
-
```ruby
|
279
|
-
require 'ggplot'
|
280
|
-
|
281
|
-
R.png("figures/dose_len.png")
|
282
|
-
|
283
|
-
e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
|
284
|
-
print e + R.geom_boxplot
|
285
|
-
|
286
|
-
R.dev__off
|
287
|
-
```
|
216
|
+
<img src="/home/rbotafogo/desenv/galaaz/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.svg" width="50%" />
|
288
217
|
|
289
218
|
[//]: # (Including the 'png' file generated above. In future releases)
|
290
219
|
[//]: # (of gKnit, the figures should be automatically saved and the name)
|
291
220
|
[//]: # (taken from the chunk 'label' and possibly chunk parameters)
|
292
221
|
|
293
|
-
![](https://gist.githubusercontent.com/rbotafogo/5538d6c679a59f4d56179b2c030e8d28/raw/96db2729e02ced0f9336216d87d14af141c1e81b/dose_len.png)
|
294
222
|
|
295
223
|
Great! We've just managed to create and save our first plot in Ruby with only
|
296
224
|
four lines of code. We can now easily see with this plot a clear trend: as the
|
@@ -329,21 +257,6 @@ facet the plot based on the ```supp``` variable and split the plot vertically.
|
|
329
257
|
the formula to ```+:supp =~ +:all``` would split the plot horizontally.
|
330
258
|
|
331
259
|
|
332
|
-
```ruby
|
333
|
-
R.png("figures/facet_by_delivery.png")
|
334
|
-
|
335
|
-
@base_tooth = @tooth_growth.ggplot(E.aes(x: :dose, y: :len, group: :dose))
|
336
|
-
|
337
|
-
@bp = @base_tooth + R.geom_boxplot +
|
338
|
-
# Split in vertical direction
|
339
|
-
R.facet_grid(+:all =~ +:supp)
|
340
|
-
|
341
|
-
puts @bp
|
342
|
-
|
343
|
-
R.dev__off
|
344
|
-
```
|
345
|
-
|
346
|
-
![](https://gist.githubusercontent.com/rbotafogo/5538d6c679a59f4d56179b2c030e8d28/raw/96db2729e02ced0f9336216d87d14af141c1e81b/facet_by_delivery.png)
|
347
260
|
|
348
261
|
It now becomes clear that although both methods of delivery have a direct
|
349
262
|
impact on tooth growth, method (OJ) is non-linear having a higher impact with smaller
|
@@ -360,16 +273,6 @@ enough to add ```fill: :dose``` to the aesthetic of boxplot. With this command
|
|
360
273
|
factor gets its own color.
|
361
274
|
|
362
275
|
|
363
|
-
```ruby
|
364
|
-
R.png("figures/facets_by_delivery_color.png")
|
365
|
-
|
366
|
-
@bp = @bp + R.geom_boxplot(E.aes(fill: :dose))
|
367
|
-
puts @bp
|
368
|
-
|
369
|
-
R.dev__off
|
370
|
-
```
|
371
|
-
|
372
|
-
![](https://gist.githubusercontent.com/rbotafogo/5538d6c679a59f4d56179b2c030e8d28/raw/96db2729e02ced0f9336216d87d14af141c1e81b/facets_by_delivery_color.png)
|
373
276
|
|
374
277
|
Facetting helps us compare the general trends for each delivery method.
|
375
278
|
Adding color allow us to compare specifically how each dosage impacts the tooth growth.
|
@@ -401,18 +304,6 @@ each of the 60 pigs in the experiment. For that, add the function 'R.geom_point
|
|
401
304
|
plot.
|
402
305
|
|
403
306
|
|
404
|
-
```ruby
|
405
|
-
R.png("figures/facets_with_points.png")
|
406
|
-
|
407
|
-
# Split in vertical direction
|
408
|
-
@bp = @bp + R.geom_point
|
409
|
-
|
410
|
-
puts @bp
|
411
|
-
|
412
|
-
R.dev__off
|
413
|
-
```
|
414
|
-
|
415
|
-
![](https://gist.githubusercontent.com/rbotafogo/5538d6c679a59f4d56179b2c030e8d28/raw/96db2729e02ced0f9336216d87d14af141c1e81b/facets_with_points.png)
|
416
307
|
|
417
308
|
Now we can see the actual distribution of all the 60 subjects. Actually, this is not
|
418
309
|
totally true. We have a hard time seing all 60 subjects. It seems that some points
|
@@ -426,16 +317,6 @@ prevents data hiding. We also add
|
|
426
317
|
color and change the shape of the points, making them even easier to see.
|
427
318
|
|
428
319
|
|
429
|
-
```ruby
|
430
|
-
R.png("figures/facets_with_jitter.png")
|
431
|
-
|
432
|
-
# Split in vertical direction
|
433
|
-
puts @bp + R.geom_jitter(shape: 23, color: "cyan3", size: 1)
|
434
|
-
|
435
|
-
R.dev__off
|
436
|
-
```
|
437
|
-
|
438
|
-
![](https://gist.githubusercontent.com/rbotafogo/5538d6c679a59f4d56179b2c030e8d28/raw/96db2729e02ced0f9336216d87d14af141c1e81b/facets_with_jitter.png)
|
439
320
|
|
440
321
|
Now we can see all 60 points in the graph. We have here a much higher information density
|
441
322
|
and we can see outliers and subjects distribution.
|
@@ -471,20 +352,6 @@ This ordering seems more natural and
|
|
471
352
|
matches with the actual order of the colors in the plot.
|
472
353
|
|
473
354
|
|
474
|
-
```ruby
|
475
|
-
R.png("figures/facets_by_delivery_color2.png")
|
476
|
-
|
477
|
-
@bp = @bp +
|
478
|
-
R.scale_fill_manual(values: R.c("cyan", "deepskyblue", "deepskyblue4"),
|
479
|
-
breaks: R.c("2","1","0.5"))
|
480
|
-
|
481
|
-
puts @bp
|
482
|
-
|
483
|
-
R.dev__off
|
484
|
-
```
|
485
|
-
|
486
|
-
![](https://gist.githubusercontent.com/rbotafogo/5538d6c679a59f4d56179b2c030e8d28/raw/96db2729e02ced0f9336216d87d14af141c1e81b/facets_by_delivery_color2.png)
|
487
|
-
|
488
355
|
|
489
356
|
## Violin Plot and Jitter
|
490
357
|
|
@@ -504,21 +371,6 @@ a boxplot known as a _violin plot_ with jittered data.
|
|
504
371
|
> The central dot represents the median average value.
|
505
372
|
|
506
373
|
|
507
|
-
```ruby
|
508
|
-
R.png("figures/violin_with_jitter.png")
|
509
|
-
|
510
|
-
@violin = @base_tooth + R.geom_violin(E.aes(fill: :dose)) +
|
511
|
-
R.facet_grid(+:all =~ +:supp) +
|
512
|
-
R.geom_jitter(shape: 23, color: "cyan3", size: 1) +
|
513
|
-
R.scale_fill_manual(values: R.c("cyan", "deepskyblue", "deepskyblue4"),
|
514
|
-
breaks: R.c("2","1","0.5"))
|
515
|
-
|
516
|
-
puts @violin
|
517
|
-
|
518
|
-
R.dev__off
|
519
|
-
```
|
520
|
-
|
521
|
-
![](https://gist.githubusercontent.com/rbotafogo/5538d6c679a59f4d56179b2c030e8d28/raw/96db2729e02ced0f9336216d87d14af141c1e81b/violin_with_jitter.png)
|
522
374
|
|
523
375
|
This plot is an alternative to the original boxplot. For the final presentation, it is
|
524
376
|
important to think which graphics will be best understood by our audience. A violin plot
|
@@ -539,26 +391,6 @@ for information about the plot (for clarity, we defined a caption variable using
|
|
539
391
|
Here Doc style).
|
540
392
|
|
541
393
|
|
542
|
-
```ruby
|
543
|
-
R.png("figures/facets_with_decorations.png", width: 540, height: 560)
|
544
|
-
|
545
|
-
caption = <<-EOT
|
546
|
-
Length of odontoblasts in 60 guinea pigs.
|
547
|
-
Each animal received one of three dose levels of vitamin C.
|
548
|
-
EOT
|
549
|
-
|
550
|
-
@decorations =
|
551
|
-
R.labs(title: "Tooth Growth: Length vs Vitamin C Dose",
|
552
|
-
subtitle: "Faceted by delivery method, OJ or VC",
|
553
|
-
x: "Dose (mg)", y: "Teeth length",
|
554
|
-
caption: caption)
|
555
|
-
|
556
|
-
puts @bp + @decorations
|
557
|
-
|
558
|
-
R.dev__off
|
559
|
-
```
|
560
|
-
|
561
|
-
![](https://gist.githubusercontent.com/rbotafogo/5538d6c679a59f4d56179b2c030e8d28/raw/225058450f4e69e5e82a01e22f69725554746893/facets_with_decorations.png)
|
562
394
|
|
563
395
|
## The Corp Theme
|
564
396
|
|
@@ -576,57 +408,6 @@ a shade o blue (color: '#00080'). Axis labels are moved near the end of the axi
|
|
576
408
|
written in 'bold'.
|
577
409
|
|
578
410
|
|
579
|
-
```ruby
|
580
|
-
module CorpTheme
|
581
|
-
|
582
|
-
R.install_and_loads 'RColorBrewer'
|
583
|
-
|
584
|
-
#---------------------------------------------------------------------------------
|
585
|
-
# face can be (1=plain, 2=bold, 3=italic, 4=bold-italic)
|
586
|
-
#---------------------------------------------------------------------------------
|
587
|
-
|
588
|
-
def self.text_element(size, face: "plain", hjust: nil)
|
589
|
-
E.element_text(color: "#000080",
|
590
|
-
face: face,
|
591
|
-
size: size,
|
592
|
-
hjust: hjust)
|
593
|
-
end
|
594
|
-
|
595
|
-
#---------------------------------------------------------------------------------
|
596
|
-
# Defines the plot theme (visualization). In this theme we remove major and minor
|
597
|
-
# grids, borders and background. We also turn-off scientific notation.
|
598
|
-
#---------------------------------------------------------------------------------
|
599
|
-
|
600
|
-
def self.global_theme(faceted = false)
|
601
|
-
|
602
|
-
R.options(scipen: 999) # turn-off scientific notation like 1e+48
|
603
|
-
# R.theme_set(R.theme_bw)
|
604
|
-
|
605
|
-
# remove major grids
|
606
|
-
gb = R.theme(panel__grid__major: E.element_blank())
|
607
|
-
# remove minor grids
|
608
|
-
gb = gb + R.theme(panel__grid__minor: E.element_blank)
|
609
|
-
# gb = R.theme(panel__grid__minor: E.element_blank)
|
610
|
-
# remove border
|
611
|
-
gb = gb + R.theme(panel__border: E.element_blank)
|
612
|
-
# remove background. When working with faceted graphs, the background makes
|
613
|
-
# it easier to see each facet, so leave it
|
614
|
-
gb = gb + R.theme(panel__background: E.element_blank) if !faceted
|
615
|
-
# Change axis font
|
616
|
-
gb = gb + R.theme(axis__text: text_element(8))
|
617
|
-
# change axis title font
|
618
|
-
gb = gb + R.theme(axis__title: text_element(10, face: "bold", hjust: 1))
|
619
|
-
# change font of title
|
620
|
-
gb = gb + R.theme(title: text_element(12, face: "bold"))
|
621
|
-
# change font of subtitle
|
622
|
-
gb = gb + R.theme(plot__subtitle: text_element(9))
|
623
|
-
# change font of captions
|
624
|
-
gb = gb + R.theme(plot__caption: text_element(8))
|
625
|
-
|
626
|
-
end
|
627
|
-
|
628
|
-
end
|
629
|
-
```
|
630
411
|
|
631
412
|
## Final Box Plot
|
632
413
|
|
@@ -640,30 +421,11 @@ the decorations (@decorations), plus the corporate theme.
|
|
640
421
|
Here is our final boxplot, without jitter.
|
641
422
|
|
642
423
|
|
643
|
-
```ruby
|
644
|
-
R.png("figures/final_box_plot.png", width: 540, height: 560)
|
645
|
-
|
646
|
-
puts @bp + @decorations + CorpTheme.global_theme(faceted: true)
|
647
|
-
|
648
|
-
R.dev__off
|
649
|
-
```
|
650
|
-
|
651
|
-
![](https://gist.githubusercontent.com/rbotafogo/5538d6c679a59f4d56179b2c030e8d28/raw/225058450f4e69e5e82a01e22f69725554746893/final_box_plot.png)
|
652
424
|
|
653
425
|
And here is the final violin plot, with jitter and the same look and feel of the corporate
|
654
426
|
boxplot.
|
655
427
|
|
656
428
|
|
657
|
-
```ruby
|
658
|
-
R.png("figures/final_violin_plot.png", width: 540, height: 560)
|
659
|
-
|
660
|
-
puts @violin + @decorations + CorpTheme.global_theme(faceted: true)
|
661
|
-
|
662
|
-
R.dev__off
|
663
|
-
```
|
664
|
-
|
665
|
-
|
666
|
-
![]https://gist.githubusercontent.com/rbotafogo/5538d6c679a59f4d56179b2c030e8d28/raw/225058450f4e69e5e82a01e22f69725554746893/final_violin_plot.png
|
667
429
|
|
668
430
|
## Another View
|
669
431
|
|
@@ -672,28 +434,6 @@ dose and not by supplement. This shows how easy it is to create new plots by ju
|
|
672
434
|
changing small statement on the _grammar of graphics_.
|
673
435
|
|
674
436
|
|
675
|
-
```ruby
|
676
|
-
R.png("figures/facet_by_dose.png", width: 540, height: 560)
|
677
|
-
|
678
|
-
caption = <<-EOT
|
679
|
-
Length of odontoblasts in 60 guinea pigs.
|
680
|
-
Each animal received one of three dose levels of vitamin C.
|
681
|
-
EOT
|
682
|
-
|
683
|
-
@bp = @tooth_growth.ggplot(E.aes(x: :supp, y: :len, group: :supp)) +
|
684
|
-
R.geom_boxplot(E.aes(fill: :supp)) + R.facet_grid(+:all =~ +:dose) +
|
685
|
-
R.scale_fill_manual(values: R.c("cyan", "deepskyblue4")) +
|
686
|
-
R.labs(title: "Tooth Growth: Length by Dose",
|
687
|
-
subtitle: "Faceted by dose",
|
688
|
-
x: "Delivery method", y: "Teeth length",
|
689
|
-
caption: caption) +
|
690
|
-
CorpTheme.global_theme(faceted: true)
|
691
|
-
puts @bp
|
692
|
-
|
693
|
-
R.dev__off
|
694
|
-
```
|
695
|
-
|
696
|
-
![](https://gist.githubusercontent.com/rbotafogo/5538d6c679a59f4d56179b2c030e8d28/raw/96db2729e02ced0f9336216d87d14af141c1e81b/facet_by_dose.png)
|
697
437
|
|
698
438
|
# Conclusion
|
699
439
|
|
@@ -3,55 +3,55 @@
|
|
3
3
|
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' viewBox='0 0 506 506' style='fill:transparent'>
|
4
4
|
<g style='stroke-width:1.4226377952755906;stroke-linejoin:round;stroke-linecap:round'>
|
5
5
|
<rect x='0' y='0' width='506' height='506' style='stroke:#FFFFFF;fill:#FFFFFF'/>
|
6
|
-
<rect x='
|
6
|
+
<rect x='31' y='6' width='469' height='473' style='stroke:rgb(0,0,0);stroke-opacity:0.000;fill:#EBEBEB'/>
|
7
7
|
</g><g style='stroke-width:0.7113188976377953;stroke-linejoin:round;stroke-linecap:butt'>
|
8
|
-
<polyline points='
|
9
|
-
<polyline points='
|
10
|
-
<polyline points='
|
11
|
-
<polyline points='
|
8
|
+
<polyline points='31,446 500,446' style='stroke:#FFFFFF'/>
|
9
|
+
<polyline points='31,301 500,301' style='stroke:#FFFFFF'/>
|
10
|
+
<polyline points='31,156 500,156' style='stroke:#FFFFFF'/>
|
11
|
+
<polyline points='31,11 500,11' style='stroke:#FFFFFF'/>
|
12
12
|
</g><g style='stroke-width:1.4226377952755906;stroke-linejoin:round;stroke-linecap:butt'>
|
13
|
-
<polyline points='
|
14
|
-
<polyline points='
|
15
|
-
<polyline points='
|
16
|
-
<polyline points='
|
17
|
-
<polyline points='
|
18
|
-
<polyline points='
|
13
|
+
<polyline points='31,373 500,373' style='stroke:#FFFFFF'/>
|
14
|
+
<polyline points='31,228 500,228' style='stroke:#FFFFFF'/>
|
15
|
+
<polyline points='31,84 500,84' style='stroke:#FFFFFF'/>
|
16
|
+
<polyline points='119,479 119,6' style='stroke:#FFFFFF'/>
|
17
|
+
<polyline points='266,479 266,6' style='stroke:#FFFFFF'/>
|
18
|
+
<polyline points='412,479 412,6' style='stroke:#FFFFFF'/>
|
19
19
|
</g><g style='stroke-width:0.9448818897637796;stroke-linejoin:round;stroke-linecap:round'>
|
20
|
-
<circle cx='
|
20
|
+
<circle cx='119' cy='207' r='2' style='stroke:#333333;fill:#333333'/>
|
21
21
|
</g><g style='stroke-width:1.4226377952755906;stroke-linejoin:round;stroke-linecap:butt'>
|
22
|
-
<polyline points='
|
23
|
-
<polyline points='
|
22
|
+
<polyline points='119,341 119,263' style='stroke:#333333'/>
|
23
|
+
<polyline points='119,413 119,457' style='stroke:#333333'/>
|
24
24
|
</g><g style='stroke-width:1.4226377952755906;stroke-linejoin:round;stroke-linecap:round'>
|
25
|
-
<polyline points='
|
25
|
+
<polyline points='64,341 64,413 174,413 174,341 64,341 64,341' style='stroke:#333333;fill:#FFFFFF'/>
|
26
26
|
</g><g style='stroke-width:2.8452755905511813;stroke-linejoin:round;stroke-linecap:butt'>
|
27
|
-
<polyline points='
|
27
|
+
<polyline points='64,375 174,375' style='stroke:#333333'/>
|
28
28
|
</g><g style='stroke-width:1.4226377952755906;stroke-linejoin:round;stroke-linecap:butt'>
|
29
|
-
<polyline points='
|
30
|
-
<polyline points='
|
29
|
+
<polyline points='266,180 266,123' style='stroke:#333333'/>
|
30
|
+
<polyline points='266,283 266,321' style='stroke:#333333'/>
|
31
31
|
</g><g style='stroke-width:1.4226377952755906;stroke-linejoin:round;stroke-linecap:round'>
|
32
|
-
<polyline points='
|
32
|
+
<polyline points='211,180 211,283 321,283 321,180 211,180 211,180' style='stroke:#333333;fill:#FFFFFF'/>
|
33
33
|
</g><g style='stroke-width:2.8452755905511813;stroke-linejoin:round;stroke-linecap:butt'>
|
34
|
-
<polyline points='
|
34
|
+
<polyline points='211,239 321,239' style='stroke:#333333'/>
|
35
35
|
</g><g style='stroke-width:1.4226377952755906;stroke-linejoin:round;stroke-linecap:butt'>
|
36
|
-
<polyline points='
|
37
|
-
<polyline points='
|
36
|
+
<polyline points='412,115 412,27' style='stroke:#333333'/>
|
37
|
+
<polyline points='412,177 412,250' style='stroke:#333333'/>
|
38
38
|
</g><g style='stroke-width:1.4226377952755906;stroke-linejoin:round;stroke-linecap:round'>
|
39
|
-
<polyline points='358,
|
39
|
+
<polyline points='358,115 358,177 467,177 467,115 358,115 358,115' style='stroke:#333333;fill:#FFFFFF'/>
|
40
40
|
</g><g style='stroke-width:2.8452755905511813;stroke-linejoin:round;stroke-linecap:butt'>
|
41
|
-
<polyline points='358,
|
42
|
-
</g><text x='
|
43
|
-
<text x='
|
44
|
-
<text x='
|
41
|
+
<polyline points='358,142 467,142' style='stroke:#333333'/>
|
42
|
+
</g><text x='16' y='376' lengthAdjust='spacingAndGlyphs' textLength='11px' style='font-size:8.8px;fill:#4D4D4D'>10</text>
|
43
|
+
<text x='16' y='231' lengthAdjust='spacingAndGlyphs' textLength='11px' style='font-size:8.8px;fill:#4D4D4D'>20</text>
|
44
|
+
<text x='16' y='87' lengthAdjust='spacingAndGlyphs' textLength='11px' style='font-size:8.8px;fill:#4D4D4D'>30</text>
|
45
45
|
<g style='stroke-width:1.4226377952755906;stroke-linejoin:round;stroke-linecap:butt'>
|
46
|
-
<polyline points='
|
47
|
-
<polyline points='
|
48
|
-
<polyline points='
|
49
|
-
<polyline points='
|
50
|
-
<polyline points='
|
51
|
-
<polyline points='
|
52
|
-
</g><text x='
|
53
|
-
<text x='
|
54
|
-
<text x='410' y='
|
55
|
-
<text x='
|
56
|
-
<text x='13' y='
|
46
|
+
<polyline points='29,373 31,373' style='stroke:#333333'/>
|
47
|
+
<polyline points='29,228 31,228' style='stroke:#333333'/>
|
48
|
+
<polyline points='29,84 31,84' style='stroke:#333333'/>
|
49
|
+
<polyline points='119,482 119,479' style='stroke:#333333'/>
|
50
|
+
<polyline points='266,482 266,479' style='stroke:#333333'/>
|
51
|
+
<polyline points='412,482 412,479' style='stroke:#333333'/>
|
52
|
+
</g><text x='111' y='490' lengthAdjust='spacingAndGlyphs' textLength='16px' style='font-size:8.8px;fill:#4D4D4D'>0.5</text>
|
53
|
+
<text x='263' y='490' lengthAdjust='spacingAndGlyphs' textLength='5px' style='font-size:8.8px;fill:#4D4D4D'>1</text>
|
54
|
+
<text x='410' y='490' lengthAdjust='spacingAndGlyphs' textLength='5px' style='font-size:8.8px;fill:#4D4D4D'>2</text>
|
55
|
+
<text x='253' y='500' lengthAdjust='spacingAndGlyphs' textLength='26px' style='font-size:11.0px;fill:#000000'>dose</text>
|
56
|
+
<text x='13' y='252' lengthAdjust='spacingAndGlyphs' textLength='20px' style='font-size:11.0px;fill:#000000' transform='rotate(-90,13,252)'>len</text>
|
57
57
|
</svg>
|