-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rmd-Parte1.html
828 lines (585 loc) · 33.1 KB
/
Rmd-Parte1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<title>Clase 9</title>
<meta charset="utf-8" />
<meta name="author" content="Miriam Lerma" />
<script src="Rmd-Parte1_files/header-attrs-2.20/header-attrs.js"></script>
<script src="Rmd-Parte1_files/clipboard-2.0.6/clipboard.min.js"></script>
<link href="Rmd-Parte1_files/xaringanExtra-clipboard-0.2.6/xaringanExtra-clipboard.css" rel="stylesheet" />
<script src="Rmd-Parte1_files/xaringanExtra-clipboard-0.2.6/xaringanExtra-clipboard.js"></script>
<script>window.xaringanExtraClipboard(null, {"button":"Copy Code","success":"Copied!","error":"Press Ctrl+C to Copy"})</script>
<script src="Rmd-Parte1_files/kePrint-0.0.1/kePrint.js"></script>
<link href="Rmd-Parte1_files/lightable-0.0.1/lightable.css" rel="stylesheet" />
<link rel="stylesheet" href="Rmd-themer.css" type="text/css" />
</head>
<body>
<textarea id="source">
class: title-slide, center, middle
background-image: url(https://images.unsplash.com/photo-1587533042502-1209d3f2d891?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1548&q=80)
background-size: cover
# <span style=" font-weight: bold; color: #264653 !important;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: #FFFFFF !important;font-size: 60px;" >Rmarkdown</span>
# <span style=" font-weight: bold; color: #264653 !important;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: #FFFFFF !important;font-size: 60px;" >Básicos</span>
<br>
<h2><span style=" font-weight: bold; color: #264653 !important;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: #FFFFFF !important;" >Miriam Lerma</span></h2>
<h3><span style=" font-weight: bold; color: #264653 !important;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: #FFFFFF !important;" >Abril 2021</span></h3>
---
class:inverse
# Intro
- [Que es Rmd](#rmd)
- [Texto, Chunks, YAML & Knit](#texto)
- [Titulos](#titulos)
- [Cambiar parametros del chunk](#chunks)
- [Cambiar Outputs](#outputs)
- [Figuras](#figuras)
- [Tablas](#tablas)
--
## Ustedes
- Conocimientos básicos de R
- Quieren compartir sus avances con otros
- Quieren tener un buen seguimiento de lo que hicieron y poder re-hacer sus análisis con otros datos en el futuro
---
class: inverse
## Créditos & Recursos
- Material de Rmarkdown.
[<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#b7e4c7;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>RMarkdown por RStudio](https://rmarkdown.rstudio.com/lesson-2.html)
[<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#b7e4c7;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>Rmarkdown por Yihui Xie](https://bookdown.org/yihui/rmarkdown/)
[<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#b7e4c7;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>Rmarkdown por Allison Horst](https://github.com/allisonhorst/rladies-bangalore-rmarkdown)
- Tutoriales en español:
[<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#b7e4c7;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>RLadiesBuenosAires](https://www.youtube.com/watch?v=zENhUzKfCws)
- Tutoriales en ingles:
[<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#b7e4c7;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>RLadiesOslo](https://www.youtube.com/watch?v=Xn5AmUf7gDQ&t=6552s)<br>
[<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#b7e4c7;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>RLadiesFreiburg](https://www.youtube.com/watch?v=H91WSwALx1A&t=3777s)<br>
[<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#b7e4c7;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>RLadiesJohannesburgo](https://www.youtube.com/watch?v=tSrf4n7DFYI&t=55s)
- Imagen de portada
[Unsplash by Maryna Yazbeck](https://unsplash.com/@yazbeckistan)
---
name: rmd
## 1. RMarkdown
Rmarkdown es muy conveniente porque podemos exportar lo que hicimos en Rstudio a html o documentos word.
Tambien podemos crear presentaciones... <br>
.right[...de hecho esta es una presentación en Rmd.]
--
Hay **muchas** maneras de trabajar en Rmd. Solo cubriré algunas.
---
## 1.1. Teoría
Markdown es texto plano...
.right[...algo así como lo que escriben en un block de notas.]
La ventaja de Rmd es que puedes incluir mucho texto e incluso se pueden escribir tesis, libros, árticulos, páginas web y presentaciones dentro de **RStudio**.
--
Lo que lo hace especial es que en Rmd ádemas puedes incluir:
- Código y los resultados de ese código sin tener que salir de RStudio.
---
## 1.1. Teoría
Lo que hace Rmd es que "traduce" lo que escribiste en Rmd usando **PanDoc**.
.center[
<img src="https://d33wubrfki0l68.cloudfront.net/61d189fd9cdf955058415d3e1b28dd60e1bd7c9b/b739c/lesson-images/rmarkdownflow.png" width="600" />
]
---
## 1.2. Porque usar Rmd?
Al generar un **output**, la ventaja es que puedes leer lo que dice el documento, aunque no tengas R.
Por ejemplo: ustedes estan leyendo esta presentación.
--
También, podemos tener resultados de alguna función sin tener que mostrar el código y sin tener que salir y copiar los resultados en un documento word.
Entonces me permite escribir cosas como:
_Aquí quiero cargar una librería y ver el número de observaciones_
```r
library(datos)
```
```
## Warning: package 'datos' was built under R version 4.2.3
```
```r
Pingus<-pinguinos
nrow(Pingus)
```
```
## [1] 344
```
.right[y ver los resultados.]
---
## 1.3. R vs Rmd
**Consideraciones: **
Rmd tiene diferente comportamiento que R
- Rmarkdown corre en un enviroment limpio.
- Todas tus variables tienen que esta dentro de tu markdown.
- De hecho si tienes cosas en tu environment no interesa, tienen que estar dentro del documento.
- Esto asegura que es reproducible, si no tiene continuidad no corre.
---
## 1.4. Como abrir un Rmd.
File>NewFile>RMarkdown <br>
Nos va a pedir un nombre de archivo, pueden ponerle 'Prueba_Rmd'
Se vera algo así:
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/RmdNew.JPG" height="400" />
---
name: texto
## 1.5. Diferencias entre R y Rmd
Diferencias entre R y Rmd:
- yaml
- output
- chunks
- knit
... las veremos por partes.
---
## 2.1. Texto
Para escribir texto puedes usar las partes en blanco, en general se escribe igual que en cualquier programa como en tu block de notas o word.
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/RmdNew.JPG" height="400" />
Si vas a la par, despues de abrir tu documento, borra el contenido, excepto el YAML.
---
## 2.2. Texto
Solo que para utilizar formatos especiales como:
- *cursivas* hay que escribir un asterisco antes y uno después.
- **negritas** con dos asteriscos antes y uno después.
- ***cursiva y negritas*** con tres asteriscos antes y uno después.
Otras opciones: [<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#f77f00;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>Texto en Rmd](https://rmarkdown.rstudio.com/lesson-8.html)
---
class: inverse, center, middle
# Chunks
---
## 2.1. Chunks
Las partes grises son los chunks.
- Se escribe código dentro de tres tildes invertidas al inicio y al final y {r} entre corchetes.
- Podemos correr la linea del código usando la flechita verde <svg aria-hidden="true" role="img" viewBox="0 0 448 512" style="height:1em;width:0.88em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#f77f00;overflow:visible;position:relative;"><path d="M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"/></svg>, el boton **Run** en la parte de arriba del editor de codigo o **ctrl+enter**.
- El resultado va a aparecer en el documento en lugar de en la consola.
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/RmdNew.JPG" height="400" />
---
## 2.2. Chunks
Podemos agregar nuevos chunks usando **Ctrl+Alt+I** , usando **back ticks** o dandole click al simbolo que tiene una C en rectangulo verde y un simbolo de **+**.
El código de R tiene que estar dentro de estas partes grises para que se ejecute.
**Errores comunes son**:
- No cerrar los corchetes **{}**
- No tener las tres tildes invertidas al inicio y al final
- Poner codigo fuera de los chunks
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/RmdNew.JPG" height="400" />
---
class: inverse, center, middle
# 3. YAML
---
## 3.1. YAML
YAML significa _“YAML Ain’t Markup Language”._
Por default aparece: title, author, date, **output**.
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/YAML.JPG" height="400" />
---
## 3.2. YAML
Al cambiar el YAML cambiara la informacion que aparece en nuestro reporte.<br>
Al cambiar el output, podemos generar reportes en diferentes formatos.
**Errores comunes**
Al renderizar nuestro reporte, alguna parte no es compatible con Pandoc (o LateX)
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/YAML.JPG" height="400" />
---
class: inverse, center, middle
# 4. Knitr
---
## 4.1. Knitr
Es el boton que aparece en la parte de arriba, es como una bolita azul con agujas de tejer.
Este boton **knitr** es una herramienta que permite la generación de informes dinámico usando R.
**Nota**: cada vez que usamos knit se guardan los cambios en el documento.
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/knitr.jpg" height="400" />
---
class: inverse, center, middle
# 5. Ejercicios
---
## 5. Ejercicios juntos
1. Abrir RStudio
2. Abrir un archivo Rmd (File>NewFile>Rmd)
3. Darle un nombre al archivo y escribir tu nombre
4. Borrar todo menos el YAML
5. Agregar código en un chunk
6. Crear una gráfica en un chunk
7. Agregar texto
Recuerden, pueden usar el botón verde para correr el código y **Ctrl+Alt+I** para crear un nuevo chunk.
---
## 5. Ejercicios juntos
Para el texto:
Escribe:
'Voy a cargar datos de pinguinos'
- Pon dos **asteriscos** antes y después de la palabra 'pinguinos'.
- Pon un **asterisco** antes y después de la palabra 'datos'.
- Pon tres **asteriscos** antes y después de la palabra 'cargar'.
Para la parte de la código pueden escribir:
```r
library(datos)
Pingus<-pinguinos
nrow(Pingus) #numero de observaciones
```
Para el gráfico:
```r
library(ggplot2)
ggplot(Pingus, aes(x=largo_pico_mm, y=alto_pico_mm))+
geom_point()
```
Dale click a knit. Te va a pedir que le des un nombre y te van a aparecer muchas cosas en lo que era antes tu terminal (ahora esta en la pestaña R Markdown).
Espera a que aparezca tu html <svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#f77f00;overflow:visible;position:relative;"><path d="M256,8C119,8,8,119,8,256S119,504,256,504,504,393,504,256,393,8,256,8Zm92.49,313h0l-20,25a16,16,0,0,1-22.49,2.5h0l-67-49.72a40,40,0,0,1-15-31.23V112a16,16,0,0,1,16-16h32a16,16,0,0,1,16,16V256l58,42.5A16,16,0,0,1,348.49,321Z"/></svg>
---
class: inverse, center, middle
# Más funcionalidades
---
name: titulos
# 6.1. Titulos
Si queremos poner títulos usar #.<br>
- Para titulo de primer nivel #.<br>
- Para titulo de segundo nivel ##.<br>
- Para titulo de tercer nivel ###.<br>
**Importante**: Hay que poner dos espacios o br dentro de '<' y '>' donde quieras que pase a la siguiente linea.
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/RmdNew.JPG" height="350" />
---
## 6.2. Navegar con titulos
Una vez hayamos incluido titulos podemos navegar dentro de nuestro archivo.
Dale click al cuadrito con las rayitas junto al compás o usa **Crtl+Shft+O**.
Deben aparecer los títulos para navegar en nuestro lado derecho.
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/Navegar.JPG" height="400" />
---
name: chunks
# 7. Chunks
En la parte de los chunks podemos agregar:
- **echo=TRUE** para mostrar el codigo en el output.
- **eval=TRUE** para ejecuta el codigo, **eval=FALSE** para no ejecutar el codigo.
- **warning=FALSE** para evitar que aparezcan las advertencias.
- **message=FALSE** para evitar que aparezcan mensajes, por ejemplo cuando cargamos librerías.
Otras opciones: [<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#f77f00;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg> chunk options](https://rmarkdown.rstudio.com/lesson-3.html)
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/echo.jpg" height="400" />
---
## 7.2. Chunks
**Buenas practicas**:
Darle nombres a tus code chunks (despues del { y la r).
Esto porque si tenemos algún problema sabemos donde se genero el problema.
El nombre de este chunk es 'setup'
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/echo.jpg" height="400" />
---
# 8. Outputs
Los documentos se pueden exportar en diversos formatos, los más comunes son word, pdf y html.
Pros y contras de usar uno o el otro.
- **word**: lo podemos compartir mas fácilmente, y muchas revistas requieren word.
- **pdf**: se puede compartir mas fácilmente, pero no es tan fácil de editar.
- **html**: se puede incluir toda clase de contenidos⭐, pero resulta poco familiar.
---
name: outputs
## 8.1. Outputs
Para cambiar el output, hay que especificarlo en el YAML, o darle click a la flechita <svg aria-hidden="true" role="img" viewBox="0 0 320 512" style="height:1em;width:0.62em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#f77f00;overflow:visible;position:relative;"><path d="M41 288h238c21.4 0 32.1 25.9 17 41L177 448c-9.4 9.4-24.6 9.4-33.9 0L24 329c-15.1-15.1-4.4-41 17-41z"/></svg> de Knit y seleccionar la opción deseada.
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/Outputs.JPG" height="400" />
Para modificar el formato de word [ve aquí](https://rfortherestofus.com/2020/07/word-reference-documents-rmarkdown/)
---
class: inverse, center, middle
# 9. Ejercicios
---
# 9.1. Ejercicios
- Agregar titulos y navegar usando los titulos
- Cambiar los datos en el YAML
- Crear outputs en word, pdf y html
- Cambiar opciones en los chunks
**Nota**<br>
Puede que necesiten instalar tinytex<br>
```r
tinytex::install_tinytex()
```
- [<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#f77f00;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>Que es tiny tex?](https://yihui.org/tinytex/)
---
# 9.1. Ejercicios
- Agregar titulos y navegar usando los titulos
Copia y **agrega un numeral en cada sección.**
Introducción
Aquí escribiré mi introducción
Métodos
Aquí escribiré mis métodos
Análisis preliminares
Aquí escribiré mis análisis
Resultados
Aquí escribiré mis resultados
Discusión
Aquí escribiré mi discusión
**Nota** Hay que agregar un espacio entre los títulos
---
# 9.1. Ejercicios
- Cambiar los datos en el YAML<br>
Fecha de hoy<br>
Tu nombre<br>
- Crear outputs en word, pdf y html<br>
word_document y knit<br>
pdf_document y knit<br>
html_document y knit<br>
- Cambiar opciones en los chunks<br>
Agrega echo=FALSE en tu primer chunk<br>
Agrega message=FALSE en tu primer chunk<br>
Agrega eval=FALSE en tu segundo chunk<br>
**Recuerda darle al boton knit para ver la diferencia, o usar la pestaña Viewer**
---
class: center, middle, inverse
# 10. Imágenes, Graficas y Tablas
---
name: figuras
## 10.1. Imágenes
- Para agregar imágenes desde **tu computadora** se usa signo de admiración, corchetes, y dentro la dirección de la imagen.
Por ejemplo:
![ pie de foto ] (Imágenes/Foto.jpg)
- Desde **Internet** se puede usar:
knitr::include_graphics('') con el enlace de la imagen entre paréntesis.
Por ejemplo:<br>
```r
knitr::include_graphics('https://images.unsplash.com/photo-1523224339316-5e4ae73929cc?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=666&q=80')
```
.center[
<img src="https://images.unsplash.com/photo-1523224339316-5e4ae73929cc?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=666&q=80" height="200" />
]
---
## 10.2. Graficas
Si creamos un plot con ggplot en un chunk y queremos ajustar el tamaño, el tamaño se puede definir dentro de los corchetes { } y usando:
- fig.height
- fig.width
Para hacer zoom de tu grafico, debajo de tu chunk aparece un cuadrito con una flechita.
<img src="https://raw.githubusercontent.com/MiriamLL/Curso_CIAD/main/Figuras/Figuras.JPG" height="400" />
---
name: tablas
## 10.3. Tablas
Hay muchos paquetes para incluir tablas. El básico es knitr + kable dentro de un **chunk**.
```r
knitr::kable(TablaPinguinos)
```
---
## 10.4. Tablas
Para recrear la tabla anterior el codigo es:
```r
library(tidyverse)
TablaPinguinos<-Pingus %>% group_by(especie,sexo) %>%
drop_na(masa_corporal_g)%>% summarise(mean = mean(masa_corporal_g), n = n())
```
---
## 10.4. Tablas
Otra opción es usando la librería {kableExtra}
```r
library(kableExtra)
```
Para incluir la tabla en el texto se usa la función {kbl}
```r
kbl(TablaResultados,
booktabs = T, caption = "Demo Table") %>% #Titulo
kable_styling(latex_options = c("striped", "hold_position"),
full_width = F)
```
<table class="table" style="width: auto !important; margin-left: auto; margin-right: auto;">
<caption>Demo Table</caption>
<thead>
<tr>
<th style="text-align:left;"> term </th>
<th style="text-align:right;"> estimate </th>
<th style="text-align:right;"> std.error </th>
<th style="text-align:right;"> statistic </th>
<th style="text-align:right;"> p.value </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> (Intercept) </td>
<td style="text-align:right;"> 23.0680794 </td>
<td style="text-align:right;"> 3.0342298 </td>
<td style="text-align:right;"> 7.602614 </td>
<td style="text-align:right;"> 0e+00 </td>
</tr>
<tr>
<td style="text-align:left;"> alto_pico_mm </td>
<td style="text-align:right;"> 0.8570263 </td>
<td style="text-align:right;"> 0.1650259 </td>
<td style="text-align:right;"> 5.193285 </td>
<td style="text-align:right;"> 7e-07 </td>
</tr>
</tbody>
</table>
---
## 10.4. Tablas
Para recrear la tabla el codigo es:
```r
Adelia<-Pingus%>%filter(especie=='Adelia') #filtra los datos
lm_Adelia<-lm(data=Adelia,largo_pico_mm ~ alto_pico_mm) #crea el modelo
TablaResultados<-broom::tidy(lm_Adelia)#crea la tabla
```
Si no recuerdan el código es de la clase de [<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#f77f00;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>modelo lineal](https://miriamll.github.io/Curso_CIAD/Clase7)
---
## 10.4. Tablas
Finalmente, para agregar descripción a la tabla se puede agregar **caption**
```r
knitr::kable(TablaPinguinos, caption = "Tabla 1. Ejemplo.")
```
---
class: inverse, center, middle
# 11. Ejercicios
---
# 11. Ejercicios
- Importa una imagen desde Internet usando [<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#f77f00;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>Unsplash](https://unsplash.com/) o desde tu computadora
- Crea una tabla
- Cambia el tamaño de tu gráfico
---
## 11.1. Ejercicios
- Escribe knitr::include_graphics() dentro de un chunk, copia y pega el link de alguna foto de internet o alguna desde tu computadora. <br>
No olvides las comillas.
- Escribe knitr::kable y dentro el nombre de tu tabla <br>
Puedes crear una tabla usando
```r
library(tidyverse)
library(datos)
Pingus<-datos::pinguinos
TablaPinguinos<-Pingus %>%
group_by(especie,sexo) %>%
drop_na(masa_corporal_g)%>%
summarise(mean = mean(masa_corporal_g), n = n())
knitr::kable(TablaPinguinos)
```
- Agrega fig.height, fig.width a tu figura. Prueba con 1,5,10.
```r
#{r, fig.width=1,fig.height=1}
ggplot(Pingus, aes(x=largo_pico_mm, y=alto_pico_mm))+
geom_point()
```
---
class: left, inverse
# Contacto
Recapitulando
- [Que es Rmd](#rmd)
- [Texto, Chunks, YAML & Knit](#texto)
- [Titulos](#titulos)
- [Cambiar parametros del chunk](#chunks)
- [Cambiar Outputs](#outputs)
- [Figuras](#figuras)
- [Tablas](#tablas)
.right[
Para dudas, comentarios y sugerencias:
Escríbeme a miriamjlerma@gmail.com
Este material esta accesible y se encuentra en
mi [<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#b7e4c7;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>github](https://github.com/MiriamLL/Curso_CIAD/)
y mi [<svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#b7e4c7;overflow:visible;position:relative;"><path d="M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z"/></svg>página](https://www.miriam-lerma.com)
]
<br>
.center[
<h3><svg aria-hidden="true" role="img" viewBox="0 0 576 512" style="height:1em;width:1.12em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#74c69d;overflow:visible;position:relative;"><path d="M280.37 148.26L96 300.11V464a16 16 0 0 0 16 16l112.06-.29a16 16 0 0 0 15.92-16V368a16 16 0 0 1 16-16h64a16 16 0 0 1 16 16v95.64a16 16 0 0 0 16 16.05L464 480a16 16 0 0 0 16-16V300L295.67 148.26a12.19 12.19 0 0 0-15.3 0zM571.6 251.47L488 182.56V44.05a12 12 0 0 0-12-12h-56a12 12 0 0 0-12 12v72.61L318.47 43a48 48 0 0 0-61 0L4.34 251.47a12 12 0 0 0-1.6 16.9l25.5 31A12 12 0 0 0 45.15 301l235.22-193.74a12.19 12.19 0 0 1 15.3 0L530.9 301a12 12 0 0 0 16.9-1.6l25.5-31a12 12 0 0 0-1.7-16.93z"/></svg>[Volver ](https://www.miriam-lerma.com/teaching.html)
]
</textarea>
<style data-target="print-only">@media screen {.remark-slide-container{display:block;}.remark-slide-scaler{box-shadow:none;}}</style>
<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script>var slideshow = remark.create({
"highlightStyle": "github",
"highlightLines": true,
"countIncrementalSlides": true
});
if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {
window.dispatchEvent(new Event('resize'));
});
(function(d) {
var s = d.createElement("style"), r = d.querySelector(".remark-slide-scaler");
if (!r) return;
s.type = "text/css"; s.innerHTML = "@page {size: " + r.style.width + " " + r.style.height +"; }";
d.head.appendChild(s);
})(document);
(function(d) {
var el = d.getElementsByClassName("remark-slides-area");
if (!el) return;
var slide, slides = slideshow.getSlides(), els = el[0].children;
for (var i = 1; i < slides.length; i++) {
slide = slides[i];
if (slide.properties.continued === "true" || slide.properties.count === "false") {
els[i - 1].className += ' has-continuation';
}
}
var s = d.createElement("style");
s.type = "text/css"; s.innerHTML = "@media print { .has-continuation { display: none; } }";
d.head.appendChild(s);
})(document);
// delete the temporary CSS (for displaying all slides initially) when the user
// starts to view slides
(function() {
var deleted = false;
slideshow.on('beforeShowSlide', function(slide) {
if (deleted) return;
var sheets = document.styleSheets, node;
for (var i = 0; i < sheets.length; i++) {
node = sheets[i].ownerNode;
if (node.dataset["target"] !== "print-only") continue;
node.parentNode.removeChild(node);
}
deleted = true;
});
})();
// add `data-at-shortcutkeys` attribute to <body> to resolve conflicts with JAWS
// screen reader (see PR #262)
(function(d) {
let res = {};
d.querySelectorAll('.remark-help-content table tr').forEach(tr => {
const t = tr.querySelector('td:nth-child(2)').innerText;
tr.querySelectorAll('td:first-child .key').forEach(key => {
const k = key.innerText;
if (/^[a-z]$/.test(k)) res[k] = t; // must be a single letter (key)
});
});
d.body.setAttribute('data-at-shortcutkeys', JSON.stringify(res));
})(document);
(function() {
"use strict"
// Replace <script> tags in slides area to make them executable
var scripts = document.querySelectorAll(
'.remark-slides-area .remark-slide-container script'
);
if (!scripts.length) return;
for (var i = 0; i < scripts.length; i++) {
var s = document.createElement('script');
var code = document.createTextNode(scripts[i].textContent);
s.appendChild(code);
var scriptAttrs = scripts[i].attributes;
for (var j = 0; j < scriptAttrs.length; j++) {
s.setAttribute(scriptAttrs[j].name, scriptAttrs[j].value);
}
scripts[i].parentElement.replaceChild(s, scripts[i]);
}
})();
(function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
links[i].target = '_blank';
}
}
})();
// adds .remark-code-has-line-highlighted class to <pre> parent elements
// of code chunks containing highlighted lines with class .remark-code-line-highlighted
(function(d) {
const hlines = d.querySelectorAll('.remark-code-line-highlighted');
const preParents = [];
const findPreParent = function(line, p = 0) {
if (p > 1) return null; // traverse up no further than grandparent
const el = line.parentElement;
return el.tagName === "PRE" ? el : findPreParent(el, ++p);
};
for (let line of hlines) {
let pre = findPreParent(line);
if (pre && !preParents.includes(pre)) preParents.push(pre);
}
preParents.forEach(p => p.classList.add("remark-code-has-line-highlighted"));
})(document);</script>
<script>
slideshow._releaseMath = function(el) {
var i, text, code, codes = el.getElementsByTagName('code');
for (i = 0; i < codes.length;) {
code = codes[i];
if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
text = code.textContent;
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
/^\$\$(.|\s)+\$\$$/.test(text) ||
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
code.outerHTML = code.innerHTML; // remove <code></code>
continue;
}
}
i++;
}
};
slideshow._releaseMath(document);
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML';
if (location.protocol !== 'file:' && /^https?:/.test(script.src))
script.src = script.src.replace(/^https?:/, '');
document.getElementsByTagName('head')[0].appendChild(script);
})();
</script>
</body>
</html>