-
Notifications
You must be signed in to change notification settings - Fork 42
/
etendre-ggplot2.html
1445 lines (1349 loc) · 121 KB
/
etendre-ggplot2.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
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="fr" xml:lang="fr">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<title>Étendre ggplot2</title>
<script src="libs/header-attrs-2.25/header-attrs.js"></script>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="libs/bootstrap-3.3.5/css/paper.min.css" rel="stylesheet" />
<script src="libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<style>h1 {font-size: 34px;}
h1.title {font-size: 38px;}
h2 {font-size: 30px;}
h3 {font-size: 24px;}
h4 {font-size: 18px;}
h5 {font-size: 16px;}
h6 {font-size: 12px;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }</style>
<script src="libs/navigation-1.1/tabsets.js"></script>
<link href="libs/pagedtable-1.1/css/pagedtable.css" rel="stylesheet" />
<script src="libs/pagedtable-1.1/js/pagedtable.js"></script>
<link href="libs/anchor-sections-1.1.0/anchor-sections.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections-hash.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.1.0/anchor-sections.js"></script>
<meta name="robots" content="index, follow">
<link rel="stylesheet" href="./include/analyse-R.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js"></script>
<script type="text/javascript" src="./libs/bigfoot-2.1.4/bigfoot.min.js"></script>
<link rel="stylesheet" href="./libs/bigfoot-2.1.4/bigfoot-number.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
<link rel="stylesheet" href="./libs/colorbox-1.6.1/colorbox.css" />
<script type="text/javascript" src="./libs/colorbox-1.6.1/jquery.colorbox-min.js"></script>
<!--- favicon --->
<link rel="apple-touch-icon" sizes="57x57" href="./images/favicon/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="./images/favicon/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="./images/favicon/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="./images/favicon/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="./images/favicon/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="./images/favicon/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="./images/favicon/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="./images/favicon/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="./images/favicon/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="./images/favicon/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="./images/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="./images/favicon/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="./images/favicon/favicon-16x16.png">
<link rel="manifest" href="./images/favicon/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="./images/favicon/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-86STMQ5JPT"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-86STMQ5JPT');
</script>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
<style type="text/css">
code {
white-space: pre;
}
.sourceCode {
overflow: visible;
}
</style>
<style type="text/css" data-origin="pandoc">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
var sheets = document.styleSheets;
for (var i = 0; i < sheets.length; i++) {
if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
try { var rules = sheets[i].cssRules; } catch (e) { continue; }
var j = 0;
while (j < rules.length) {
var rule = rules[j];
// check if there is a div.sourceCode rule
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") {
j++;
continue;
}
var style = rule.style.cssText;
// check if color or background-color is set
if (rule.style.color === '' && rule.style.backgroundColor === '') {
j++;
continue;
}
// replace div.sourceCode by a pre.sourceCode rule
sheets[i].deleteRule(j);
sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
}
}
})();
</script>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
details > summary > p:only-child {
display: inline;
}
pre code {
padding: 0;
}
</style>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "\e259";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "\e258";
font-family: 'Glyphicons Halflings';
border: none;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
</head>
<body>
<div class="container-fluid main-container">
<nav>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href=".">analyse-R</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="manipuler" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Manipuler <span class="caret"></span></a>
<ul class="dropdown-menu multi-column columns-3" role="menu" id="menu_manipuler">
<div class="row">
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li class="dropdown-header">Prise en main</li>
<li><a href="presentation-et-philosophie.html">Présentation et Philosophie</a></li>
<li><a href="installation-de-R-et-RStudio.html">Installation de <strong>R</strong> et <strong>RStudio</strong></a></li>
<li><a href="premier-contact.html">Premier contact</a></li>
<li><a href="premier-travail-avec-les-donnees.html">Premier travail avec des données</a></li>
<li><a href="extensions.html">Extensions (installation, mise à jour)</a></li>
<li><a href="introduction-au-tidyverse.html">Introduction au <strong>tidyverse</strong></a></li>
<li><a href="vecteurs-indexation-et-assignation.html">Vecteurs, indexation et assignation</a></li>
<li><a href="listes-et-tableaux-de-donnees.html">Listes et Tableaux de données</a></li>
<li><a href="facteurs-et-vecteurs-labellises.html">Facteurs et vecteurs labellisés</a></li>
<li><a href="organiser-ses-fichiers.html">Organiser ses fichiers</a></li>
<li><a href="import-de-donnees.html">Import de données</a></li>
<li><a href="ou-trouver-de-l-aide.html">Où trouver de l'aide ?</a></li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li class="dropdown-header">Manipulation de données</li>
<li><a href="visualiser-ses-donnees.html">Visualiser ses données</a></li>
<li><a href="recodage.html">Recodage de variables</a></li>
<li><a href="manipuler-les-donnees-avec-dplyr.html">Manipuler les données avec <strong>dplyr</strong></a></li>
<li><a href="manipulations-avancees-avec-data-table.html">Manipulations avancées avec <strong>data.table</strong></a></li>
<li><a href="tris.html">Tris</a></li>
<li><a href="sous-ensembles.html">Sous-ensembles</a></li>
<li><a href="fusion-de-tables.html">Fusion de tables</a></li>
<li><a href="gestion-des-dates.html">Gestion des dates</a></li>
<li><a href="fonctions-a-fenetre.html">Fonctions à fenêtre</a></li>
<li><a href="manipuler-du-texte.html">Manipuler du texte avec <strong>stringr</strong></a></li>
<li><a href="reorganiser-ses-donnees-avec-tidyr.html">Réorganiser ses données avec <strong>tidyr</strong></a></li>
<!--<li><a href="scraping.html.old">Scraping</a></li>-->
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li class="dropdown-header">Exporter</li>
<li><a href="export-de-donnees.html">Export de données</a></li>
<li><a href="export-de-graphiques.html">Export de graphiques</a></li>
</ul>
</div>
</div>
</ul>
</li>
<li class="dropdown">
<a href="analyser" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Analyser <span class="caret"></span></a>
<ul class="dropdown-menu multi-column columns-3" role="menu" id="menu_analyser">
<div class="row">
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li class="dropdown-header">Statistiques introductives</li>
<li><a href="statistique-univariee.html">Statistique univariée</a></li>
<li><a href="statistique-bivariee.html">Statistique bivariée</a></li>
<li><a href="intro-ggplot2.html">Introduction à <strong>ggplot2</strong>, la grammaire des graphiques</a></li>
<li><a href="graphiques-bivaries-ggplot2.html">Graphiques univariés et bivariés avec <strong>ggplot2</strong></a></li>
<li><a href="donnees-ponderees.html">Données pondérées</a></li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li class="dropdown-header">Statistiques intermédiaires</li>
<li><a href="intervalles-de-confiance.html">Intervalles de confiance</a></li>
<li><a href="comparaisons-moyennes-et-proportions.html">Comparaisons (moyennes et proportions)</a></li>
<li><a href="definir-un-plan-d-echantillonnage-complexe.html">Définir un plan d'échantillonnage complexe avec <strong>survey</strong></a></li>
<li><a href="regression-lineaire.html">Régression linéaire</a></li>
<li><a href="regression-logistique.html">Régression logistique binaire, multinomiale et ordinale</a></li>
<li><a href="analyse-des-correspondances-multiples.html">Analyse des correspondances multiples (ACM)</a></li>
<li><a href="classification-ascendante-hierarchique.html">Classification ascendante hiérarchique (CAH)</a></li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li class="dropdown-header">Statistiques avancées</li>
<li><a href="gtsummary.html">Tableaux statistiques avancés avec <strong>gtsummary</strong></a></li>
<li><a href="effets-d-interaction.html">Effets d'interaction dans un modèle</a></li>
<li><a href="multicolinearite.html">Multicolinéarité dans la régression</a></li>
<li><a href="modeles.html">Quel type de modèles choisir ?</a></li>
<li><a href="analyse-de-survie.html">Analyse de survie</a></li>
<li><a href="analyse-de-sequences.html">Analyse de séquences</a></li>
<!--<li><a href="modeles-a-effets-aleatoires.html">Modèles à effets aléatoires (modèles mixtes et GEE)</a></li>-->
<li><a href="trajectoires-de-soins.html">Trajectoires de soins : un exemple de données longitudinales</a></li>
<li><a href="analyse-de-reseaux.html">Analyse de réseaux</a></li>
<li><a href="analyse-spatiale.html">Analyse spatiale</a></li>
<li><a href="analyse-textuelle.html">Analyse textuelle</a></li>
</ul>
</div>
</div>
</ul>
</li>
<li class="dropdown">
<a href="approfondir" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Approfondir <span class="caret"></span></a>
<ul class="dropdown-menu multi-column columns-3" role="menu" id="menu_approfondir">
<div class="row">
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li class="dropdown-header">Graphiques</li>
<li><a href="ggplot2.html"><strong>ggplot2</strong> et la grammaire des graphiques</a></li>
<li><a href="etendre-ggplot2.html">Étendre <strong>ggplot2</strong></a></li>
<li><a href="combiner-plusieurs-graphiques.html">Combiner plusieurs graphiques</a></li>
<li><a href="exemples-graphiques-avances.html">Exemples de graphiques avancés</a></li>
<li><a href="graphiques-interactifs.html">Graphiques interactifs</a></li>
<li><a href="lattice-graphiques-et-formules.html"><strong>lattice</strong> : graphiques et formules</a></li>
<li><a href="cartes.html">Cartes</a></li>
<li><a href="autres-extensions-graphiques.html">Autres extensions graphiques</a></li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li class="dropdown-header">Programmation</li>
<li><a href="conditions-et-comparaisons.html">Conditions et comparaisons</a></li>
<li><a href="formules.html">Formules</a></li>
<li><a href="structures-conditionnelles.html">Structures conditionnelles</a></li>
<li><a href="vectorisation.html">Vectorisation (dont <strong>purrr</strong>)</a></li>
<li><a href="expressions-regulieres.html">Expressions régulières</a></li>
<!--<li class="dev"><a href="ecrire-ses-propres-fonctions.html">Écrire ses propres fonctions</a></li>-->
<li><a href="rmarkdown-les-rapports-automatises.html"><strong>R Markdown</strong> : les rapports automatisés</a></li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li class="dropdown-header">Divers</li>
<li><a href="formater-nombres.html">Mettre en forme des nombres avec <strong>scales</strong></a></li>
<li><a href="couleurs.html">Couleurs et Palettes</a></li>
<li><a href="annotations-mathematiques.html">Annotations mathématiques</a></li>
<li><a href="calculer-un-age.html">Calculer un âge</a></li>
<li><a href="diagramme-de-lexis.html">Diagramme de Lexis</a></li>
</ul>
</div>
</div>
</ul>
</li>
<li class="dropdown">
<a href="index" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Index <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu" id="menu_naviguer">
<li><a href="index-des-concepts.html">Index des concepts</a></li>
<li><a href="index-des-fonctions.html">Index des fonctions</a></li>
<li><a href="index-des-extensions.html">Index des extensions</a></li>
</ul>
</li>
<li><a href="analyse-R.pdf">PDF</a></li>
<li><a href="https://larmarange.github.io/guide-R/">guide-R</a></li>
<li><a href="https://larmarange.github.io/webin-R/">webin-R</a></li>
<li><a href="https://www.youtube.com/c/webinR"><i class="fa fa-youtube" aria-hidden="true"></i></a></li>
<!--<li><a href="https://github.com/larmarange/analyse-R">GitHub</a></li>-->
</ul>
<form id="rechercher" class="navbar-form navbar-right" role="search" style="padding-top: 5px;" method="get" action="https://duckduckgo.com/">
<div class="form-group">
<input name="q" type="text" class="form-control input-sm" placeholder="Rechercher">
</div>
<button type="submit" class="btn btn-default btn-sm" name="Rechercher">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
</button>
</form>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
</nav>
<div class="row">
<div class="visible-lg">
<a href="https://github.com/larmarange/analyse-R"><img style="position: absolute; top: 60px; left: 40px; border: 0;" src="images/fork_me.png" alt="Contribuer sur GitHub"></a>
</div>
<div class="col-sm-9" role="main">
<article>
<div id="header">
<h1 class="title toc-ignore">Étendre ggplot2</h1>
</div>
<div id="TOC">
<ul>
<li><a href="#nouvelles-géométries" id="toc-nouvelles-géométries">Nouvelles géométries</a>
<ul>
<li><a href="#étiquettes-non-superposées" id="toc-étiquettes-non-superposées">Étiquettes non superposées</a></li>
<li><a href="#graphiques-en-sucettes-lollipop" id="toc-graphiques-en-sucettes-lollipop">Graphiques en sucettes (<em>lollipop</em>)</a></li>
<li><a href="#graphique-dhaltères-dumbbell" id="toc-graphique-dhaltères-dumbbell">Graphique d’haltères (<em>dumbbell</em>)</a></li>
<li><a href="#points-reliés-pointpath" id="toc-points-reliés-pointpath">Points reliés (<em>pointpath</em>)</a></li>
<li><a href="#accolades-de-comparaison-bracket" id="toc-accolades-de-comparaison-bracket">Accolades de comparaison (<em>bracket</em>)</a></li>
<li><a href="#diagramme-en-crêtes-ridges" id="toc-diagramme-en-crêtes-ridges">Diagramme en crêtes (<em>ridges</em>)</a></li>
<li><a href="#graphique-en-gaufres-waffle" id="toc-graphique-en-gaufres-waffle">Graphique en gaufres (<em>waffle</em>)</a></li>
<li><a href="#graphique-en-mosaïque-mosaic-plot" id="toc-graphique-en-mosaïque-mosaic-plot">Graphique en mosaïque (<em>mosaic plot</em>)</a></li>
<li><a href="#représentations-graphiques-des-distributions-et-de-lincertitude" id="toc-représentations-graphiques-des-distributions-et-de-lincertitude">Représentations graphiques des distributions et de l’incertitude</a></li>
<li><a href="#graphique-de-pirates-alternative-aux-boîtes-à-moustache-pirat-plot" id="toc-graphique-de-pirates-alternative-aux-boîtes-à-moustache-pirat-plot">Graphique de pirates : alternative aux boîtes à moustache (<em>pirat plot</em>)</a></li>
<li><a href="#nuages-de-pluie-raincloud-plots" id="toc-nuages-de-pluie-raincloud-plots">Nuages de pluie (<em>raincloud plots</em>)</a></li>
<li><a href="#demi-géométries" id="toc-demi-géométries">Demi-géométries</a></li>
<li><a href="#annotations-avec-des-formes-gémoétriques" id="toc-annotations-avec-des-formes-gémoétriques">Annotations avec des formes gémoétriques</a></li>
</ul></li>
<li><a href="#axes-légende-et-facettes" id="toc-axes-légende-et-facettes">Axes, légende et facettes</a>
<ul>
<li><a href="#texte-mis-en-forme" id="toc-texte-mis-en-forme">Texte mis en forme</a></li>
<li><a href="#axes-limités" id="toc-axes-limités">Axes <q>limités</q></a></li>
<li><a href="#répéter-les-étiquettes-des-axes-sur-des-facettes" id="toc-répéter-les-étiquettes-des-axes-sur-des-facettes">Répéter les étiquettes des axes sur des facettes</a></li>
<li><a href="#encoches-mineures-sur-les-axes" id="toc-encoches-mineures-sur-les-axes">Encoches mineures sur les axes</a></li>
<li><a href="#relations-imbriquées" id="toc-relations-imbriquées">Relations imbriquées</a></li>
<li><a href="#combinaison-de-variables-sur-laxe-des-x" id="toc-combinaison-de-variables-sur-laxe-des-x">Combinaison de variables sur l’axe des X</a></li>
<li><a href="#des-facettes-paginées-diviser-en-plusieurs-sous-graphiques" id="toc-des-facettes-paginées-diviser-en-plusieurs-sous-graphiques">Des facettes paginées (diviser en plusieurs sous-graphiques)</a></li>
</ul></li>
<li><a href="#cartes" id="toc-cartes">Cartes</a></li>
<li><a href="#graphiques-complexes" id="toc-graphiques-complexes">Graphiques complexes</a>
<ul>
<li><a href="#graphiques-divergents" id="toc-graphiques-divergents">Graphiques divergents</a></li>
<li><a href="#pyramides-des-âges" id="toc-pyramides-des-âges">Pyramides des âges</a></li>
<li><a href="#graphiques-interactifs" id="toc-graphiques-interactifs">Graphiques interactifs</a></li>
<li><a href="#graphiques-animés" id="toc-graphiques-animés">Graphiques animés</a></li>
<li><a href="#surligner-certaines-données" id="toc-surligner-certaines-données">Surligner certaines données</a></li>
</ul></li>
<li><a href="#thèmes-et-couleurs" id="toc-thèmes-et-couleurs">Thèmes et couleurs</a>
<ul>
<li><a href="#palettes-de-couleurs" id="toc-palettes-de-couleurs">Palettes de couleurs</a></li>
<li><a href="#hrbrthemes" id="toc-hrbrthemes">hrbrthemes</a></li>
<li><a href="#ggthemes" id="toc-ggthemes">ggthemes</a></li>
</ul></li>
<li><a href="#combiner-plusieurs-graphiques" id="toc-combiner-plusieurs-graphiques">Combiner plusieurs graphiques</a></li>
</ul>
</div>
<div class="webin-R">
<p>Ce chapitre est évoqué dans le webin-R #13 (exemples de graphiques avancés) sur <a href="https://youtu.be/5sD4Z8bTlMM">YouTube</a>.</p>
<p>Ce chapitre est évoqué dans le webin-R #14 (exemples de graphiques avancés - 2) sur <a href="https://youtu.be/iJT46MGSQA8">YouTube</a>.</p>
</div>
<p>De nombreuses extensions permettent d’étendre les possibilités graphiques de <code class="pkg">ggplot2</code>. Certaines ont déjà été abordées dans les différents chapitres d’<strong>analyse-R</strong>. Le présent chapitre ne se veut pas exhaustif et ne présente qu’une sélection choisie d’extensions.</p>
<p>Le site <strong>ggplot2 extensions</strong> (<a href="https://exts.ggplot2.tidyverse.org/gallery/" class="uri">https://exts.ggplot2.tidyverse.org/gallery/</a>) recense diverses extensions pour <code class="pkg">ggplot2</code>.</p>
<p>Pour une présentation des fonctions de base et des concepts de <code class="pkg">ggplot2</code>, on pourra se référer au <a href="ggplot2.html">chapitre dédié</a> ainsi qu’au deux chapitres introductifs : <a href="intro-ggplot2.html">introduction à ggplot2</a> et <a href="graphiques-bivaries-ggplot2.html">graphiques bivariés avec ggplot2</a>.</p>
<p>Pour trouver l’inspiration et des exemples de code, rien ne vaut l’excellent site <a href="https://www.r-graph-gallery.com/" class="uri">https://www.r-graph-gallery.com/</a>.</p>
<div id="nouvelles-géométries" class="section level2 hasAnchor">
<h2 class="hasAnchor">Nouvelles géométries<a href="#nouvelles-géométries" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<div id="étiquettes-non-superposées" class="section level3 hasAnchor">
<h3 class="hasAnchor">Étiquettes non superposées<a href="#étiquettes-non-superposées" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>Lorsque l’on affiche des étiquettes de texte, ces dernières peuvent se supperposer lorsqu’elles sont proches. Les géométries <code data-pkg="ggrepel" data-rdoc="geom_label_repel">geom_text_repel</code> et <code data-pkg="ggrepel">geom_label_repel</code> de l’extension <code class="pkg">ggrepel</code> prennent en compte la position des différentes étiquettes pour éviter qu’elles ne se chevauchent.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="fu">library</span>(ggrepel)</span>
<span id="cb1-3"><a href="#cb1-3" tabindex="-1"></a><span class="fu">library</span>(ggrepel)</span>
<span id="cb1-4"><a href="#cb1-4" tabindex="-1"></a></span>
<span id="cb1-5"><a href="#cb1-5" tabindex="-1"></a>dat <span class="ot"><-</span> <span class="fu">subset</span>(mtcars, wt <span class="sc">></span> <span class="fl">2.75</span> <span class="sc">&</span> wt <span class="sc"><</span> <span class="fl">3.45</span>)</span>
<span id="cb1-6"><a href="#cb1-6" tabindex="-1"></a>dat<span class="sc">$</span>car <span class="ot"><-</span> <span class="fu">rownames</span>(dat)</span>
<span id="cb1-7"><a href="#cb1-7" tabindex="-1"></a>p <span class="ot"><-</span> <span class="fu">ggplot</span>(dat) <span class="sc">+</span></span>
<span id="cb1-8"><a href="#cb1-8" tabindex="-1"></a> <span class="fu">aes</span>(wt, mpg, <span class="at">label =</span> car) <span class="sc">+</span></span>
<span id="cb1-9"><a href="#cb1-9" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="at">color =</span> <span class="st">"red"</span>)</span>
<span id="cb1-10"><a href="#cb1-10" tabindex="-1"></a></span>
<span id="cb1-11"><a href="#cb1-11" tabindex="-1"></a>p1 <span class="ot"><-</span> p <span class="sc">+</span> <span class="fu">geom_text</span>() <span class="sc">+</span></span>
<span id="cb1-12"><a href="#cb1-12" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"geom_text()"</span>)</span>
<span id="cb1-13"><a href="#cb1-13" tabindex="-1"></a>p2 <span class="ot"><-</span> p <span class="sc">+</span> <span class="fu">geom_text_repel</span>() <span class="sc">+</span></span>
<span id="cb1-14"><a href="#cb1-14" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"geom_text_repel()"</span>)</span>
<span id="cb1-15"><a href="#cb1-15" tabindex="-1"></a></span>
<span id="cb1-16"><a href="#cb1-16" tabindex="-1"></a>cowplot<span class="sc">::</span><span class="fu">plot_grid</span>(p1, p2, <span class="at">nrow =</span> <span class="dv">1</span>)</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-1-1.png" width="1050" /></p>
<p>Pour plus d’informations : <a href="https://ggrepel.slowkow.com/" class="uri">https://ggrepel.slowkow.com/</a></p>
</div>
<div id="graphiques-en-sucettes-lollipop" class="section level3 hasAnchor">
<h3 class="hasAnchor">Graphiques en sucettes (<em>lollipop</em>)<a href="#graphiques-en-sucettes-lollipop" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>L’extension <code class="pkg">ggalt</code> propose une géométrie <code data-pkg="ggalt">geom_lollipop</code> permettant de réaliser des graphiques dit en <q>sucettes</q>.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a>df <span class="ot"><-</span> <span class="fu">read.csv</span>(<span class="at">text =</span> <span class="st">"category,pct</span></span>
<span id="cb2-2"><a href="#cb2-2" tabindex="-1"></a><span class="st">Other,0.09</span></span>
<span id="cb2-3"><a href="#cb2-3" tabindex="-1"></a><span class="st">South Asian/South Asian Americans,0.12</span></span>
<span id="cb2-4"><a href="#cb2-4" tabindex="-1"></a><span class="st">Interngenerational/Generational,0.21</span></span>
<span id="cb2-5"><a href="#cb2-5" tabindex="-1"></a><span class="st">S Asian/Asian Americans,0.25</span></span>
<span id="cb2-6"><a href="#cb2-6" tabindex="-1"></a><span class="st">Muslim Observance,0.29</span></span>
<span id="cb2-7"><a href="#cb2-7" tabindex="-1"></a><span class="st">Africa/Pan Africa/African Americans,0.34</span></span>
<span id="cb2-8"><a href="#cb2-8" tabindex="-1"></a><span class="st">Gender Equity,0.34</span></span>
<span id="cb2-9"><a href="#cb2-9" tabindex="-1"></a><span class="st">Disability Advocacy,0.49</span></span>
<span id="cb2-10"><a href="#cb2-10" tabindex="-1"></a><span class="st">European/European Americans,0.52</span></span>
<span id="cb2-11"><a href="#cb2-11" tabindex="-1"></a><span class="st">Veteran,0.54</span></span>
<span id="cb2-12"><a href="#cb2-12" tabindex="-1"></a><span class="st">Pacific Islander/Pacific Islander Americans,0.59</span></span>
<span id="cb2-13"><a href="#cb2-13" tabindex="-1"></a><span class="st">Non-Traditional Students,0.61</span></span>
<span id="cb2-14"><a href="#cb2-14" tabindex="-1"></a><span class="st">Religious Equity,0.64</span></span>
<span id="cb2-15"><a href="#cb2-15" tabindex="-1"></a><span class="st">Caribbean/Caribbean Americans,0.67</span></span>
<span id="cb2-16"><a href="#cb2-16" tabindex="-1"></a><span class="st">Latino/Latina,0.69</span></span>
<span id="cb2-17"><a href="#cb2-17" tabindex="-1"></a><span class="st">Middle Eastern Heritages and Traditions,0.73</span></span>
<span id="cb2-18"><a href="#cb2-18" tabindex="-1"></a><span class="st">Trans-racial Adoptee/Parent,0.76</span></span>
<span id="cb2-19"><a href="#cb2-19" tabindex="-1"></a><span class="st">LBGTQ/Ally,0.79</span></span>
<span id="cb2-20"><a href="#cb2-20" tabindex="-1"></a><span class="st">Mixed Race,0.80</span></span>
<span id="cb2-21"><a href="#cb2-21" tabindex="-1"></a><span class="st">Jewish Heritage/Observance,0.85</span></span>
<span id="cb2-22"><a href="#cb2-22" tabindex="-1"></a><span class="st">International Students,0.87"</span>, <span class="at">stringsAsFactors =</span> <span class="cn">FALSE</span>, <span class="at">sep =</span> <span class="st">","</span>, <span class="at">header =</span> <span class="cn">TRUE</span>)</span>
<span id="cb2-23"><a href="#cb2-23" tabindex="-1"></a></span>
<span id="cb2-24"><a href="#cb2-24" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb2-25"><a href="#cb2-25" tabindex="-1"></a><span class="fu">library</span>(ggalt)</span>
<span id="cb2-26"><a href="#cb2-26" tabindex="-1"></a><span class="fu">library</span>(scales)</span>
<span id="cb2-27"><a href="#cb2-27" tabindex="-1"></a></span>
<span id="cb2-28"><a href="#cb2-28" tabindex="-1"></a><span class="fu">ggplot</span>(df) <span class="sc">+</span></span>
<span id="cb2-29"><a href="#cb2-29" tabindex="-1"></a> <span class="fu">aes</span>(<span class="at">y =</span> <span class="fu">reorder</span>(category, pct), <span class="at">x =</span> pct) <span class="sc">+</span></span>
<span id="cb2-30"><a href="#cb2-30" tabindex="-1"></a> <span class="fu">geom_lollipop</span>(<span class="at">point.colour =</span> <span class="st">"steelblue"</span>, <span class="at">point.size =</span> <span class="dv">2</span>, <span class="at">horizontal =</span> <span class="cn">TRUE</span>) <span class="sc">+</span></span>
<span id="cb2-31"><a href="#cb2-31" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">expand =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="dv">0</span>), <span class="at">labels =</span> percent, <span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">1</span>, <span class="at">by =</span> <span class="fl">0.2</span>), <span class="at">limits =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="dv">1</span>)) <span class="sc">+</span></span>
<span id="cb2-32"><a href="#cb2-32" tabindex="-1"></a> <span class="fu">labs</span>(</span>
<span id="cb2-33"><a href="#cb2-33" tabindex="-1"></a> <span class="at">x =</span> <span class="cn">NULL</span>, <span class="at">y =</span> <span class="cn">NULL</span>,</span>
<span id="cb2-34"><a href="#cb2-34" tabindex="-1"></a> <span class="at">title =</span> <span class="st">"SUNY Cortland Multicultural Alumni survey results"</span>,</span>
<span id="cb2-35"><a href="#cb2-35" tabindex="-1"></a> <span class="at">subtitle =</span> <span class="st">"Ranked by race, ethnicity, home land and orientation</span><span class="sc">\n</span><span class="st">among the top areas of concern"</span>,</span>
<span id="cb2-36"><a href="#cb2-36" tabindex="-1"></a> <span class="at">caption =</span> <span class="st">"Data from http://stephanieevergreen.com/lollipop/"</span></span>
<span id="cb2-37"><a href="#cb2-37" tabindex="-1"></a> ) <span class="sc">+</span></span>
<span id="cb2-38"><a href="#cb2-38" tabindex="-1"></a> <span class="fu">theme_minimal</span>()</span></code></pre></div>
<pre><code>Warning: Using the `size` aesthetic with geom_segment was deprecated
in ggplot2 3.4.0.
ℹ Please use the `linewidth` aesthetic instead.</code></pre>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-2-1.png" width="1050" /></p>
</div>
<div id="graphique-dhaltères-dumbbell" class="section level3 hasAnchor">
<h3 class="hasAnchor">Graphique d’haltères (<em>dumbbell</em>)<a href="#graphique-dhaltères-dumbbell" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>L’extension <code class="pkg">ggalt</code> propose une géométrie <code data-pkg="ggalt">geom_dumbbell</code> permettant de réaliser des graphiques dit en <q>haltères</q>.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a><span class="fu">library</span>(ggalt)</span>
<span id="cb4-2"><a href="#cb4-2" tabindex="-1"></a>df <span class="ot"><-</span> <span class="fu">data.frame</span>(</span>
<span id="cb4-3"><a href="#cb4-3" tabindex="-1"></a> <span class="at">trt =</span> LETTERS[<span class="dv">1</span><span class="sc">:</span><span class="dv">5</span>],</span>
<span id="cb4-4"><a href="#cb4-4" tabindex="-1"></a> <span class="at">l =</span> <span class="fu">c</span>(<span class="dv">20</span>, <span class="dv">40</span>, <span class="dv">10</span>, <span class="dv">30</span>, <span class="dv">50</span>),</span>
<span id="cb4-5"><a href="#cb4-5" tabindex="-1"></a> <span class="at">r =</span> <span class="fu">c</span>(<span class="dv">70</span>, <span class="dv">50</span>, <span class="dv">30</span>, <span class="dv">60</span>, <span class="dv">80</span>)</span>
<span id="cb4-6"><a href="#cb4-6" tabindex="-1"></a>)</span>
<span id="cb4-7"><a href="#cb4-7" tabindex="-1"></a></span>
<span id="cb4-8"><a href="#cb4-8" tabindex="-1"></a><span class="fu">ggplot</span>(df) <span class="sc">+</span></span>
<span id="cb4-9"><a href="#cb4-9" tabindex="-1"></a> <span class="fu">aes</span>(<span class="at">y =</span> trt, <span class="at">x =</span> l, <span class="at">xend =</span> r) <span class="sc">+</span></span>
<span id="cb4-10"><a href="#cb4-10" tabindex="-1"></a> <span class="fu">geom_dumbbell</span>(</span>
<span id="cb4-11"><a href="#cb4-11" tabindex="-1"></a> <span class="at">size =</span> <span class="dv">3</span>,</span>
<span id="cb4-12"><a href="#cb4-12" tabindex="-1"></a> <span class="at">color =</span> <span class="st">"#e3e2e1"</span>,</span>
<span id="cb4-13"><a href="#cb4-13" tabindex="-1"></a> <span class="at">colour_x =</span> <span class="st">"#5b8124"</span>,</span>
<span id="cb4-14"><a href="#cb4-14" tabindex="-1"></a> <span class="at">colour_xend =</span> <span class="st">"#bad744"</span></span>
<span id="cb4-15"><a href="#cb4-15" tabindex="-1"></a> ) <span class="sc">+</span></span>
<span id="cb4-16"><a href="#cb4-16" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">x =</span> <span class="cn">NULL</span>, <span class="at">y =</span> <span class="cn">NULL</span>) <span class="sc">+</span></span>
<span id="cb4-17"><a href="#cb4-17" tabindex="-1"></a> <span class="fu">theme_minimal</span>()</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-3-1.png" width="1050" /></p>
</div>
<div id="points-reliés-pointpath" class="section level3 hasAnchor">
<h3 class="hasAnchor">Points reliés (<em>pointpath</em>)<a href="#points-reliés-pointpath" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>L’extension <code>ggh4x</code> propose une géométrie <code data-pkg="ggh4x">geom_pointpath</code> pour afficher des points reliés entre eux par un tiret. La géométrie <code data-pkg="lemon">geom_pointpath</code> est également proposée par l’extension <code class="pkg">lemon</code>.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" tabindex="-1"></a><span class="fu">library</span>(ggh4x)</span>
<span id="cb5-2"><a href="#cb5-2" tabindex="-1"></a><span class="fu">ggplot</span>(pressure) <span class="sc">+</span></span>
<span id="cb5-3"><a href="#cb5-3" tabindex="-1"></a> <span class="fu">aes</span>(<span class="at">x =</span> temperature, <span class="at">y =</span> pressure) <span class="sc">+</span></span>
<span id="cb5-4"><a href="#cb5-4" tabindex="-1"></a> <span class="fu">geom_pointpath</span>()</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-4-1.png" width="1050" /></p>
</div>
<div id="accolades-de-comparaison-bracket" class="section level3 hasAnchor">
<h3 class="hasAnchor">Accolades de comparaison (<em>bracket</em>)<a href="#accolades-de-comparaison-bracket" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>La géométrie <code data-pkg="ggpubr">geom_braket</code> de l’extension <code class="pkg">ggpubr</code> permets d’ajouter sur un graphique des accolades de comparaison entre groupes.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" tabindex="-1"></a><span class="fu">library</span>(ggpubr)</span>
<span id="cb6-2"><a href="#cb6-2" tabindex="-1"></a>df <span class="ot"><-</span> ToothGrowth</span>
<span id="cb6-3"><a href="#cb6-3" tabindex="-1"></a>df<span class="sc">$</span>dose <span class="ot"><-</span> <span class="fu">factor</span>(df<span class="sc">$</span>dose)</span>
<span id="cb6-4"><a href="#cb6-4" tabindex="-1"></a></span>
<span id="cb6-5"><a href="#cb6-5" tabindex="-1"></a><span class="fu">ggplot</span>(df) <span class="sc">+</span></span>
<span id="cb6-6"><a href="#cb6-6" tabindex="-1"></a> <span class="fu">aes</span>(<span class="at">x =</span> dose, <span class="at">y =</span> len) <span class="sc">+</span></span>
<span id="cb6-7"><a href="#cb6-7" tabindex="-1"></a> <span class="fu">geom_boxplot</span>() <span class="sc">+</span></span>
<span id="cb6-8"><a href="#cb6-8" tabindex="-1"></a> <span class="fu">geom_bracket</span>(</span>
<span id="cb6-9"><a href="#cb6-9" tabindex="-1"></a> <span class="at">xmin =</span> <span class="st">"0.5"</span>, <span class="at">xmax =</span> <span class="st">"1"</span>, <span class="at">y.position =</span> <span class="dv">30</span>,</span>
<span id="cb6-10"><a href="#cb6-10" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"t-test, p < 0.05"</span></span>
<span id="cb6-11"><a href="#cb6-11" tabindex="-1"></a> )</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-5-1.png" width="1050" /></p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" tabindex="-1"></a><span class="fu">ggplot</span>(df) <span class="sc">+</span></span>
<span id="cb7-2"><a href="#cb7-2" tabindex="-1"></a> <span class="fu">aes</span>(<span class="at">x =</span> dose, <span class="at">y =</span> len) <span class="sc">+</span></span>
<span id="cb7-3"><a href="#cb7-3" tabindex="-1"></a> <span class="fu">geom_boxplot</span>() <span class="sc">+</span></span>
<span id="cb7-4"><a href="#cb7-4" tabindex="-1"></a> <span class="fu">geom_bracket</span>(</span>
<span id="cb7-5"><a href="#cb7-5" tabindex="-1"></a> <span class="at">xmin =</span> <span class="fu">c</span>(<span class="st">"0.5"</span>, <span class="st">"1"</span>),</span>
<span id="cb7-6"><a href="#cb7-6" tabindex="-1"></a> <span class="at">xmax =</span> <span class="fu">c</span>(<span class="st">"1"</span>, <span class="st">"2"</span>),</span>
<span id="cb7-7"><a href="#cb7-7" tabindex="-1"></a> <span class="at">y.position =</span> <span class="fu">c</span>(<span class="dv">30</span>, <span class="dv">35</span>),</span>
<span id="cb7-8"><a href="#cb7-8" tabindex="-1"></a> <span class="at">label =</span> <span class="fu">c</span>(<span class="st">"***"</span>, <span class="st">"**"</span>),</span>
<span id="cb7-9"><a href="#cb7-9" tabindex="-1"></a> <span class="at">tip.length =</span> <span class="fl">0.01</span></span>
<span id="cb7-10"><a href="#cb7-10" tabindex="-1"></a> )</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-5-2.png" width="1050" /></p>
<p>Plus d’informations : <a href="https://rpkgs.datanovia.com/ggpubr/" class="uri">https://rpkgs.datanovia.com/ggpubr/</a></p>
</div>
<div id="diagramme-en-crêtes-ridges" class="section level3 hasAnchor">
<h3 class="hasAnchor">Diagramme en crêtes (<em>ridges</em>)<a href="#diagramme-en-crêtes-ridges" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>L’extension <code class="pkg">ggridges</code> fournit une géométrie <code data-pkg="ggridges">geom_density_ridges_gradient</code> pour la création de diagramme en crêtes.</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" tabindex="-1"></a><span class="fu">library</span>(ggridges)</span>
<span id="cb8-2"><a href="#cb8-2" tabindex="-1"></a><span class="fu">ggplot</span>(lincoln_weather, <span class="fu">aes</span>(<span class="at">x =</span> <span class="st">`</span><span class="at">Mean Temperature [F]</span><span class="st">`</span>, <span class="at">y =</span> Month, <span class="at">fill =</span> <span class="fu">stat</span>(x))) <span class="sc">+</span></span>
<span id="cb8-3"><a href="#cb8-3" tabindex="-1"></a> <span class="fu">geom_density_ridges_gradient</span>(<span class="at">scale =</span> <span class="dv">3</span>, <span class="at">rel_min_height =</span> <span class="fl">0.01</span>) <span class="sc">+</span></span>
<span id="cb8-4"><a href="#cb8-4" tabindex="-1"></a> <span class="fu">scale_fill_viridis_c</span>(<span class="at">name =</span> <span class="st">"Temp. [F]"</span>, <span class="at">option =</span> <span class="st">"C"</span>) <span class="sc">+</span></span>
<span id="cb8-5"><a href="#cb8-5" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Temperatures in Lincoln NE in 2016"</span>) <span class="sc">+</span></span>
<span id="cb8-6"><a href="#cb8-6" tabindex="-1"></a> <span class="fu">theme_ridges</span>()</span></code></pre></div>
<pre><code>Warning: `stat(x)` was deprecated in ggplot2 3.4.0.
ℹ Please use `after_stat(x)` instead.</code></pre>
<pre><code>Picking joint bandwidth of 3.37</code></pre>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-6-1.png" width="1050" /></p>
<p>Plus d’informations : <a href="https://wilkelab.org/ggridges/" class="uri">https://wilkelab.org/ggridges/</a></p>
</div>
<div id="graphique-en-gaufres-waffle" class="section level3 hasAnchor">
<h3 class="hasAnchor">Graphique en gaufres (<em>waffle</em>)<a href="#graphique-en-gaufres-waffle" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>L’extension <code class="pkg">waffle</code> propose <code data-pkg="waffle">geom_waffle</code> pour des graphiques dits en <q>gaufres</q>.</p>
<p>ATTENTION : elle s’installe avec la commande <code>install.packages("waffle", repos = "https://cinc.rud.is")</code>.</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" tabindex="-1"></a><span class="fu">library</span>(waffle)</span>
<span id="cb11-2"><a href="#cb11-2" tabindex="-1"></a>xdf <span class="ot"><-</span> <span class="fu">data.frame</span>(</span>
<span id="cb11-3"><a href="#cb11-3" tabindex="-1"></a> <span class="at">parts =</span> <span class="fu">factor</span>(<span class="fu">rep</span>(month.abb[<span class="dv">1</span><span class="sc">:</span><span class="dv">3</span>], <span class="dv">3</span>), <span class="at">levels =</span> month.abb[<span class="dv">1</span><span class="sc">:</span><span class="dv">3</span>]),</span>
<span id="cb11-4"><a href="#cb11-4" tabindex="-1"></a> <span class="at">vals =</span> <span class="fu">c</span>(<span class="dv">10</span>, <span class="dv">20</span>, <span class="dv">30</span>, <span class="dv">6</span>, <span class="dv">14</span>, <span class="dv">40</span>, <span class="dv">30</span>, <span class="dv">20</span>, <span class="dv">10</span>),</span>
<span id="cb11-5"><a href="#cb11-5" tabindex="-1"></a> <span class="at">fct =</span> <span class="fu">c</span>(<span class="fu">rep</span>(<span class="st">"Thing 1"</span>, <span class="dv">3</span>), <span class="fu">rep</span>(<span class="st">"Thing 2"</span>, <span class="dv">3</span>), <span class="fu">rep</span>(<span class="st">"Thing 3"</span>, <span class="dv">3</span>))</span>
<span id="cb11-6"><a href="#cb11-6" tabindex="-1"></a>)</span>
<span id="cb11-7"><a href="#cb11-7" tabindex="-1"></a></span>
<span id="cb11-8"><a href="#cb11-8" tabindex="-1"></a><span class="fu">ggplot</span>(xdf) <span class="sc">+</span></span>
<span id="cb11-9"><a href="#cb11-9" tabindex="-1"></a> <span class="fu">aes</span>(<span class="at">fill =</span> parts, <span class="at">values =</span> vals) <span class="sc">+</span></span>
<span id="cb11-10"><a href="#cb11-10" tabindex="-1"></a> <span class="fu">geom_waffle</span>() <span class="sc">+</span></span>
<span id="cb11-11"><a href="#cb11-11" tabindex="-1"></a> <span class="fu">facet_wrap</span>(<span class="sc">~</span>fct) <span class="sc">+</span></span>
<span id="cb11-12"><a href="#cb11-12" tabindex="-1"></a> <span class="fu">scale_fill_manual</span>(</span>
<span id="cb11-13"><a href="#cb11-13" tabindex="-1"></a> <span class="at">name =</span> <span class="cn">NULL</span>,</span>
<span id="cb11-14"><a href="#cb11-14" tabindex="-1"></a> <span class="at">values =</span> <span class="fu">c</span>(<span class="st">"#a40000"</span>, <span class="st">"#c68958"</span>, <span class="st">"#ae6056"</span>),</span>
<span id="cb11-15"><a href="#cb11-15" tabindex="-1"></a> <span class="at">labels =</span> <span class="fu">c</span>(<span class="st">"Fruit"</span>, <span class="st">"Sammich"</span>, <span class="st">"Pizza"</span>)</span>
<span id="cb11-16"><a href="#cb11-16" tabindex="-1"></a> ) <span class="sc">+</span></span>
<span id="cb11-17"><a href="#cb11-17" tabindex="-1"></a> <span class="fu">coord_equal</span>() <span class="sc">+</span></span>
<span id="cb11-18"><a href="#cb11-18" tabindex="-1"></a> <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
<span id="cb11-19"><a href="#cb11-19" tabindex="-1"></a> <span class="fu">theme_enhance_waffle</span>()</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-7-1.png" width="1050" /></p>
<p>Plus d’informations : <a href="https://github.com/hrbrmstr/waffle" class="uri">https://github.com/hrbrmstr/waffle</a></p>
</div>
<div id="graphique-en-mosaïque-mosaic-plot" class="section level3 hasAnchor">
<h3 class="hasAnchor">Graphique en mosaïque (<em>mosaic plot</em>)<a href="#graphique-en-mosaïque-mosaic-plot" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>L’extension <code class="pkg">ggmosaic</code> permets de réaliser des graphiques en mosaïque avec <code data-pkg="ggmosaic">geom_mosaic</code>.</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" tabindex="-1"></a><span class="fu">library</span>(ggmosaic)</span>
<span id="cb12-2"><a href="#cb12-2" tabindex="-1"></a><span class="fu">data</span>(titanic)</span>
<span id="cb12-3"><a href="#cb12-3" tabindex="-1"></a></span>
<span id="cb12-4"><a href="#cb12-4" tabindex="-1"></a><span class="fu">ggplot</span>(<span class="at">data =</span> titanic) <span class="sc">+</span></span>
<span id="cb12-5"><a href="#cb12-5" tabindex="-1"></a> <span class="fu">geom_mosaic</span>(<span class="fu">aes</span>(<span class="at">x =</span> <span class="fu">product</span>(Class), <span class="at">fill =</span> Survived))</span></code></pre></div>
<pre><code>Warning: `unite_()` was deprecated in tidyr 1.2.0.
ℹ Please use `unite()` instead.
ℹ The deprecated feature was likely used in the ggmosaic
package.
Please report the issue at
<]8;;https://github.com/haleyjeppson/ggmosaichttps://github.com/haleyjeppson/ggmosaic]8;;>.</code></pre>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-8-1.png" width="1050" /></p>
<p>Plus d’informations : <a href="https://cran.r-project.org/web/packages/ggmosaic/vignettes/ggmosaic.html" class="uri">https://cran.r-project.org/web/packages/ggmosaic/vignettes/ggmosaic.html</a></p>
</div>
<div id="représentations-graphiques-des-distributions-et-de-lincertitude" class="section level3 hasAnchor">
<h3 class="hasAnchor">Représentations graphiques des distributions et de l’incertitude<a href="#représentations-graphiques-des-distributions-et-de-lincertitude" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>L’extension <code class="pkg">ggdist</code> propose plusieurs géométries permettant de représenter l’incertitude autour de certaines mesures.</p>
<p><img src="images/ggdist_preview.png" /></p>
</div>
<div id="graphique-de-pirates-alternative-aux-boîtes-à-moustache-pirat-plot" class="section level3 hasAnchor">
<h3 class="hasAnchor">Graphique de pirates : alternative aux boîtes à moustache (<em>pirat plot</em>)<a href="#graphique-de-pirates-alternative-aux-boîtes-à-moustache-pirat-plot" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>Cette représentation alternative aux boîtes à moustache s’obtient avec la géométrie <code data-pkg="ggpirate">geom_pirate</code> de l’extension <code class="pkg">ggpirate</code><a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a>.</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb14-2"><a href="#cb14-2" tabindex="-1"></a><span class="fu">library</span>(ggpirate)</span>
<span id="cb14-3"><a href="#cb14-3" tabindex="-1"></a><span class="fu">ggplot</span>(mpg, <span class="fu">aes</span>(<span class="at">x =</span> class, <span class="at">y =</span> cty)) <span class="sc">+</span></span>
<span id="cb14-4"><a href="#cb14-4" tabindex="-1"></a> <span class="fu">geom_pirate</span>(<span class="fu">aes</span>(<span class="at">colour =</span> class, <span class="at">fill =</span> class)) <span class="sc">+</span></span>
<span id="cb14-5"><a href="#cb14-5" tabindex="-1"></a> <span class="fu">theme_bw</span>()</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-9-1.png" width="1050" /></p>
<p>Pour plus d’informations : <a href="https://github.com/mikabr/ggpirate" class="uri">https://github.com/mikabr/ggpirate</a></p>
</div>
<div id="nuages-de-pluie-raincloud-plots" class="section level3 hasAnchor">
<h3 class="hasAnchor">Nuages de pluie (<em>raincloud plots</em>)<a href="#nuages-de-pluie-raincloud-plots" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>Il existe encore d’autres approches graphiques pour mieux rendre compte visuellement différentes distrubutions comme les <dfn lang="en">raincloud plots</dfn>. Pour en savoir plus, on pourra se référer à un <a href="https://www.cedricscherer.com/2021/06/06/visualizing-distributions-with-raincloud-plots-with-ggplot2/">billet de blog en anglais de Cédric Scherer</a> ou encore à l’extension <code class="pkg">raincloudplots</code>.</p>
<p><img src="images/raincloud_plot_example.png" /></p>
</div>
<div id="demi-géométries" class="section level3 hasAnchor">
<h3 class="hasAnchor">Demi-géométries<a href="#demi-géométries" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>L’extension <code class="pkg">gghalves</code> propose des <q>demi-géométries</q> qui peuvent être combinées entre elles.</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" tabindex="-1"></a><span class="fu">library</span>(gghalves)</span>
<span id="cb15-2"><a href="#cb15-2" tabindex="-1"></a><span class="fu">ggplot</span>(iris, <span class="fu">aes</span>(<span class="at">x =</span> Species, <span class="at">y =</span> Sepal.Width)) <span class="sc">+</span></span>
<span id="cb15-3"><a href="#cb15-3" tabindex="-1"></a> <span class="fu">geom_half_boxplot</span>(<span class="at">fill =</span> <span class="st">"lightblue"</span>) <span class="sc">+</span></span>
<span id="cb15-4"><a href="#cb15-4" tabindex="-1"></a> <span class="fu">geom_half_violin</span>(<span class="at">side =</span> <span class="st">"r"</span>, <span class="at">fill =</span> <span class="st">"navajowhite"</span>)</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-10-1.png" width="1050" /></p>
</div>
<div id="annotations-avec-des-formes-gémoétriques" class="section level3 hasAnchor">
<h3 class="hasAnchor">Annotations avec des formes gémoétriques<a href="#annotations-avec-des-formes-gémoétriques" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>L’extension <code class="pkg">ggforce</code> fournie plusieurs géométries permettant d’annoter les points d’un nuage : <code data-pkg="ggforce">geom_mark_circle</code>, <code data-pkg="ggforce">geom_mark_ellipse</code>, <code data-pkg="ggforce">geom_mark_rect</code> et <code data-pkg="ggforce">geom_mark_hull</code>.</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" tabindex="-1"></a><span class="fu">library</span>(ggforce)</span>
<span id="cb16-2"><a href="#cb16-2" tabindex="-1"></a><span class="fu">ggplot</span>(iris, <span class="fu">aes</span>(Petal.Length, Petal.Width)) <span class="sc">+</span></span>
<span id="cb16-3"><a href="#cb16-3" tabindex="-1"></a> <span class="fu">geom_mark_rect</span>(<span class="fu">aes</span>(<span class="at">fill =</span> Species, <span class="at">label =</span> Species)) <span class="sc">+</span></span>
<span id="cb16-4"><a href="#cb16-4" tabindex="-1"></a> <span class="fu">geom_point</span>()</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-11-1.png" width="1050" /></p>
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" tabindex="-1"></a><span class="fu">ggplot</span>(iris, <span class="fu">aes</span>(Petal.Length, Petal.Width)) <span class="sc">+</span></span>
<span id="cb17-2"><a href="#cb17-2" tabindex="-1"></a> <span class="fu">geom_mark_hull</span>(<span class="fu">aes</span>(<span class="at">fill =</span> Species, <span class="at">label =</span> Species)) <span class="sc">+</span></span>
<span id="cb17-3"><a href="#cb17-3" tabindex="-1"></a> <span class="fu">geom_point</span>()</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-11-2.png" width="1050" /></p>
</div>
</div>
<div id="axes-légende-et-facettes" class="section level2 hasAnchor">
<h2 class="hasAnchor">Axes, légende et facettes<a href="#axes-légende-et-facettes" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<div id="texte-mis-en-forme" class="section level3 hasAnchor">
<h3 class="hasAnchor">Texte mis en forme<a href="#texte-mis-en-forme" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>L’extension <code class="pkg">ggtext</code> permet d’utiliser du <em>markdown</em> et du <em>HTML</em> pour une mise en forme avancée de texte (axes, titres, légendes…).</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" tabindex="-1"></a><span class="fu">library</span>(ggtext)</span>
<span id="cb18-2"><a href="#cb18-2" tabindex="-1"></a></span>
<span id="cb18-3"><a href="#cb18-3" tabindex="-1"></a><span class="fu">library</span>(tidyverse)</span>
<span id="cb18-4"><a href="#cb18-4" tabindex="-1"></a><span class="fu">library</span>(ggtext)</span>
<span id="cb18-5"><a href="#cb18-5" tabindex="-1"></a><span class="fu">library</span>(glue)</span>
<span id="cb18-6"><a href="#cb18-6" tabindex="-1"></a></span>
<span id="cb18-7"><a href="#cb18-7" tabindex="-1"></a>data <span class="ot"><-</span> <span class="fu">tibble</span>(</span>
<span id="cb18-8"><a href="#cb18-8" tabindex="-1"></a> <span class="at">bactname =</span> <span class="fu">c</span>(<span class="st">"Staphylococcaceae"</span>, <span class="st">"Moraxella"</span>, <span class="st">"Streptococcus"</span>, <span class="st">"Acinetobacter"</span>),</span>
<span id="cb18-9"><a href="#cb18-9" tabindex="-1"></a> <span class="at">OTUname =</span> <span class="fu">c</span>(<span class="st">"OTU 1"</span>, <span class="st">"OTU 2"</span>, <span class="st">"OTU 3"</span>, <span class="st">"OTU 4"</span>),</span>
<span id="cb18-10"><a href="#cb18-10" tabindex="-1"></a> <span class="at">value =</span> <span class="fu">c</span>(<span class="sc">-</span><span class="fl">0.5</span>, <span class="fl">0.5</span>, <span class="dv">2</span>, <span class="dv">3</span>)</span>
<span id="cb18-11"><a href="#cb18-11" tabindex="-1"></a>)</span>
<span id="cb18-12"><a href="#cb18-12" tabindex="-1"></a></span>
<span id="cb18-13"><a href="#cb18-13" tabindex="-1"></a>data <span class="sc">%>%</span></span>
<span id="cb18-14"><a href="#cb18-14" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb18-15"><a href="#cb18-15" tabindex="-1"></a> <span class="at">color =</span> <span class="fu">c</span>(<span class="st">"#009E73"</span>, <span class="st">"#D55E00"</span>, <span class="st">"#0072B2"</span>, <span class="st">"#000000"</span>),</span>
<span id="cb18-16"><a href="#cb18-16" tabindex="-1"></a> <span class="at">name =</span> <span class="fu">glue</span>(<span class="st">"<i style='color:{color}'>{bactname}</i> ({OTUname})"</span>),</span>
<span id="cb18-17"><a href="#cb18-17" tabindex="-1"></a> <span class="at">name =</span> <span class="fu">fct_reorder</span>(name, value)</span>
<span id="cb18-18"><a href="#cb18-18" tabindex="-1"></a> ) <span class="sc">%>%</span></span>
<span id="cb18-19"><a href="#cb18-19" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(value, name, <span class="at">fill =</span> color)) <span class="sc">+</span></span>
<span id="cb18-20"><a href="#cb18-20" tabindex="-1"></a> <span class="fu">geom_col</span>(<span class="at">alpha =</span> <span class="fl">0.5</span>) <span class="sc">+</span></span>
<span id="cb18-21"><a href="#cb18-21" tabindex="-1"></a> <span class="fu">scale_fill_identity</span>() <span class="sc">+</span></span>
<span id="cb18-22"><a href="#cb18-22" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">caption =</span> <span class="st">"Example posted on **stackoverflow.com**<br>(using made-up data)"</span>) <span class="sc">+</span></span>
<span id="cb18-23"><a href="#cb18-23" tabindex="-1"></a> <span class="fu">theme</span>(</span>
<span id="cb18-24"><a href="#cb18-24" tabindex="-1"></a> <span class="at">axis.text.y =</span> <span class="fu">element_markdown</span>(),</span>
<span id="cb18-25"><a href="#cb18-25" tabindex="-1"></a> <span class="at">plot.caption =</span> <span class="fu">element_markdown</span>(<span class="at">lineheight =</span> <span class="fl">1.2</span>)</span>
<span id="cb18-26"><a href="#cb18-26" tabindex="-1"></a> )</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-12-1.png" width="1050" /></p>
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" tabindex="-1"></a><span class="fu">ggplot</span>(mtcars, <span class="fu">aes</span>(disp, mpg)) <span class="sc">+</span></span>
<span id="cb19-2"><a href="#cb19-2" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb19-3"><a href="#cb19-3" tabindex="-1"></a> <span class="fu">labs</span>(</span>
<span id="cb19-4"><a href="#cb19-4" tabindex="-1"></a> <span class="at">title =</span> <span class="st">"<b>Fuel economy vs. engine displacement</b><br></span></span>
<span id="cb19-5"><a href="#cb19-5" tabindex="-1"></a><span class="st"> <span style = 'font-size:10pt'>Lorem ipsum *dolor sit amet,*</span></span>
<span id="cb19-6"><a href="#cb19-6" tabindex="-1"></a><span class="st"> consectetur adipiscing elit, **sed do eiusmod tempor incididunt** ut</span></span>
<span id="cb19-7"><a href="#cb19-7" tabindex="-1"></a><span class="st"> labore et dolore magna aliqua. <span style = 'color:red;'>Ut enim</span></span>
<span id="cb19-8"><a href="#cb19-8" tabindex="-1"></a><span class="st"> ad minim veniam,</span> quis nostrud exercitation ullamco laboris nisi</span></span>
<span id="cb19-9"><a href="#cb19-9" tabindex="-1"></a><span class="st"> ut aliquip ex ea commodo consequat.</span>"</span>,</span>
<span id="cb19-10"><a href="#cb19-10" tabindex="-1"></a> <span class="at">x =</span> <span class="st">"displacement (in<sup>3</sup>)"</span>,</span>
<span id="cb19-11"><a href="#cb19-11" tabindex="-1"></a> <span class="at">y =</span> <span class="st">"Miles per gallon (mpg)<br><span style = 'font-size:8pt'>A measure of</span></span>
<span id="cb19-12"><a href="#cb19-12" tabindex="-1"></a><span class="st"> the car's fuel efficiency.</span>"</span></span>
<span id="cb19-13"><a href="#cb19-13" tabindex="-1"></a> ) <span class="sc">+</span></span>
<span id="cb19-14"><a href="#cb19-14" tabindex="-1"></a> <span class="fu">theme</span>(</span>
<span id="cb19-15"><a href="#cb19-15" tabindex="-1"></a> <span class="at">plot.title.position =</span> <span class="st">"plot"</span>,</span>
<span id="cb19-16"><a href="#cb19-16" tabindex="-1"></a> <span class="at">plot.title =</span> <span class="fu">element_textbox_simple</span>(</span>
<span id="cb19-17"><a href="#cb19-17" tabindex="-1"></a> <span class="at">size =</span> <span class="dv">13</span>,</span>
<span id="cb19-18"><a href="#cb19-18" tabindex="-1"></a> <span class="at">lineheight =</span> <span class="dv">1</span>,</span>
<span id="cb19-19"><a href="#cb19-19" tabindex="-1"></a> <span class="at">padding =</span> <span class="fu">margin</span>(<span class="fl">5.5</span>, <span class="fl">5.5</span>, <span class="fl">5.5</span>, <span class="fl">5.5</span>),</span>
<span id="cb19-20"><a href="#cb19-20" tabindex="-1"></a> <span class="at">margin =</span> <span class="fu">margin</span>(<span class="dv">0</span>, <span class="dv">0</span>, <span class="fl">5.5</span>, <span class="dv">0</span>),</span>
<span id="cb19-21"><a href="#cb19-21" tabindex="-1"></a> <span class="at">fill =</span> <span class="st">"cornsilk"</span></span>
<span id="cb19-22"><a href="#cb19-22" tabindex="-1"></a> ),</span>
<span id="cb19-23"><a href="#cb19-23" tabindex="-1"></a> <span class="at">axis.title.x =</span> <span class="fu">element_textbox_simple</span>(</span>
<span id="cb19-24"><a href="#cb19-24" tabindex="-1"></a> <span class="at">width =</span> <span class="cn">NULL</span>,</span>
<span id="cb19-25"><a href="#cb19-25" tabindex="-1"></a> <span class="at">padding =</span> <span class="fu">margin</span>(<span class="dv">4</span>, <span class="dv">4</span>, <span class="dv">4</span>, <span class="dv">4</span>),</span>
<span id="cb19-26"><a href="#cb19-26" tabindex="-1"></a> <span class="at">margin =</span> <span class="fu">margin</span>(<span class="dv">4</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>),</span>
<span id="cb19-27"><a href="#cb19-27" tabindex="-1"></a> <span class="at">linetype =</span> <span class="dv">1</span>,</span>
<span id="cb19-28"><a href="#cb19-28" tabindex="-1"></a> <span class="at">r =</span> grid<span class="sc">::</span><span class="fu">unit</span>(<span class="dv">8</span>, <span class="st">"pt"</span>),</span>
<span id="cb19-29"><a href="#cb19-29" tabindex="-1"></a> <span class="at">fill =</span> <span class="st">"azure1"</span></span>
<span id="cb19-30"><a href="#cb19-30" tabindex="-1"></a> ),</span>
<span id="cb19-31"><a href="#cb19-31" tabindex="-1"></a> <span class="at">axis.title.y =</span> <span class="fu">element_textbox_simple</span>(</span>
<span id="cb19-32"><a href="#cb19-32" tabindex="-1"></a> <span class="at">hjust =</span> <span class="dv">0</span>,</span>
<span id="cb19-33"><a href="#cb19-33" tabindex="-1"></a> <span class="at">orientation =</span> <span class="st">"left-rotated"</span>,</span>
<span id="cb19-34"><a href="#cb19-34" tabindex="-1"></a> <span class="at">minwidth =</span> <span class="fu">unit</span>(<span class="dv">1</span>, <span class="st">"in"</span>),</span>
<span id="cb19-35"><a href="#cb19-35" tabindex="-1"></a> <span class="at">maxwidth =</span> <span class="fu">unit</span>(<span class="dv">2</span>, <span class="st">"in"</span>),</span>
<span id="cb19-36"><a href="#cb19-36" tabindex="-1"></a> <span class="at">padding =</span> <span class="fu">margin</span>(<span class="dv">4</span>, <span class="dv">4</span>, <span class="dv">2</span>, <span class="dv">4</span>),</span>
<span id="cb19-37"><a href="#cb19-37" tabindex="-1"></a> <span class="at">margin =</span> <span class="fu">margin</span>(<span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">2</span>, <span class="dv">0</span>),</span>
<span id="cb19-38"><a href="#cb19-38" tabindex="-1"></a> <span class="at">fill =</span> <span class="st">"lightsteelblue1"</span></span>
<span id="cb19-39"><a href="#cb19-39" tabindex="-1"></a> )</span>
<span id="cb19-40"><a href="#cb19-40" tabindex="-1"></a> )</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-12-2.png" width="1050" /></p>
</div>
<div id="axes-limités" class="section level3 hasAnchor">
<h3 class="hasAnchor">Axes <q>limités</q><a href="#axes-limités" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p><code data-pkg="lemon">coord_capped_cart</code> et <code data-pkg="lemon" data-rdoc="coord_capped_cart">coord_capped_flip</code> de l’extension <code class="pkg">lemon</code> permet de limiter le dessin des axes au minimum et au maximum. Voir l’exemple ci-dessous.</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb20-1"><a href="#cb20-1" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb20-2"><a href="#cb20-2" tabindex="-1"></a><span class="fu">library</span>(lemon)</span>
<span id="cb20-3"><a href="#cb20-3" tabindex="-1"></a>p <span class="ot"><-</span> <span class="fu">ggplot</span>(mtcars) <span class="sc">+</span></span>
<span id="cb20-4"><a href="#cb20-4" tabindex="-1"></a> <span class="fu">aes</span>(<span class="at">x =</span> cyl, <span class="at">y =</span> mpg) <span class="sc">+</span></span>
<span id="cb20-5"><a href="#cb20-5" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb20-6"><a href="#cb20-6" tabindex="-1"></a> <span class="fu">theme_classic</span>() <span class="sc">+</span></span>
<span id="cb20-7"><a href="#cb20-7" tabindex="-1"></a> <span class="fu">ggtitle</span>(<span class="st">"Axes classiques"</span>)</span>
<span id="cb20-8"><a href="#cb20-8" tabindex="-1"></a>pcapped <span class="ot"><-</span> p <span class="sc">+</span></span>
<span id="cb20-9"><a href="#cb20-9" tabindex="-1"></a> <span class="fu">coord_capped_cart</span>(<span class="at">bottom =</span> <span class="st">"both"</span>, <span class="at">left =</span> <span class="st">"both"</span>) <span class="sc">+</span></span>
<span id="cb20-10"><a href="#cb20-10" tabindex="-1"></a> <span class="fu">ggtitle</span>(<span class="st">"Axes limités"</span>)</span>
<span id="cb20-11"><a href="#cb20-11" tabindex="-1"></a>cowplot<span class="sc">::</span><span class="fu">plot_grid</span>(p, pcapped, <span class="at">nrow =</span> <span class="dv">1</span>)</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-13-1.png" width="1050" /></p>
<p>Une autre possibilité est d’avoir recours à la fonction <code data-pkg="ggh4x">guide_axis_truncated</code> de l’extension <code class="pkg">ggh4x</code>.</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" tabindex="-1"></a><span class="fu">library</span>(ggh4x)</span>
<span id="cb21-2"><a href="#cb21-2" tabindex="-1"></a><span class="fu">ggplot</span>(mtcars) <span class="sc">+</span></span>
<span id="cb21-3"><a href="#cb21-3" tabindex="-1"></a> <span class="fu">aes</span>(<span class="at">x =</span> cyl, <span class="at">y =</span> mpg) <span class="sc">+</span></span>
<span id="cb21-4"><a href="#cb21-4" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb21-5"><a href="#cb21-5" tabindex="-1"></a> <span class="fu">theme_classic</span>() <span class="sc">+</span></span>
<span id="cb21-6"><a href="#cb21-6" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">breaks =</span> <span class="fu">c</span>(<span class="dv">15</span>, <span class="dv">20</span>, <span class="dv">25</span>, <span class="dv">30</span>)) <span class="sc">+</span></span>
<span id="cb21-7"><a href="#cb21-7" tabindex="-1"></a> <span class="fu">guides</span>(</span>
<span id="cb21-8"><a href="#cb21-8" tabindex="-1"></a> <span class="at">x =</span> <span class="fu">guide_axis_truncated</span>(<span class="at">trunc_lower =</span> <span class="dv">5</span>, <span class="at">trunc_upper =</span> <span class="dv">7</span>),</span>
<span id="cb21-9"><a href="#cb21-9" tabindex="-1"></a> <span class="at">y =</span> <span class="fu">guide_axis_truncated</span>()</span>
<span id="cb21-10"><a href="#cb21-10" tabindex="-1"></a> )</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-14-1.png" width="1050" /></p>
</div>
<div id="répéter-les-étiquettes-des-axes-sur-des-facettes" class="section level3 hasAnchor">
<h3 class="hasAnchor">Répéter les étiquettes des axes sur des facettes<a href="#répéter-les-étiquettes-des-axes-sur-des-facettes" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>Lorsque l’on réalise des facettes, les étiquettes des axes ne sont pas répétées.</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb22-2"><a href="#cb22-2" tabindex="-1"></a><span class="fu">ggplot</span>(mpg) <span class="sc">+</span></span>
<span id="cb22-3"><a href="#cb22-3" tabindex="-1"></a> <span class="fu">aes</span>(displ, cty) <span class="sc">+</span></span>
<span id="cb22-4"><a href="#cb22-4" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb22-5"><a href="#cb22-5" tabindex="-1"></a> <span class="fu">facet_wrap</span>(<span class="sc">~</span>cyl)</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-15-1.png" width="1050" /></p>
<p>L’extension <code class="pkg">lemon</code> propose <code data-pkg="lemon">facet_rep_grid</code> et <code data-pkg="lemon" data-rdoc="facet_rep_grid">facet_rep_wrap</code> qui répètent les axes sur chaque facette.</p>
<div class="sourceCode" id="cb23"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" tabindex="-1"></a><span class="fu">library</span>(lemon)</span>
<span id="cb23-2"><a href="#cb23-2" tabindex="-1"></a><span class="fu">ggplot</span>(mpg) <span class="sc">+</span></span>
<span id="cb23-3"><a href="#cb23-3" tabindex="-1"></a> <span class="fu">aes</span>(displ, cty) <span class="sc">+</span></span>
<span id="cb23-4"><a href="#cb23-4" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb23-5"><a href="#cb23-5" tabindex="-1"></a> <span class="fu">facet_rep_wrap</span>(<span class="sc">~</span>cyl, <span class="at">repeat.tick.labels =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-16-1.png" width="1050" /></p>
</div>
<div id="encoches-mineures-sur-les-axes" class="section level3 hasAnchor">
<h3 class="hasAnchor">Encoches mineures sur les axes<a href="#encoches-mineures-sur-les-axes" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>Par défaut, des encoches (<em>ticks</em>) sont dessinées sur les axes uniquement pour la grille principale (<em>major breaks</em>). La fonction <code data-pkg="ggh4x">guide_axis_minor</code> de l’extension <code class="pkg">ggh4x</code> permet de rajouter des encoches aux points de la grille mineure (<em>minor breaks</em>).</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb24-1"><a href="#cb24-1" tabindex="-1"></a>p <span class="ot"><-</span> <span class="fu">ggplot</span>(mtcars) <span class="sc">+</span></span>
<span id="cb24-2"><a href="#cb24-2" tabindex="-1"></a> <span class="fu">aes</span>(<span class="at">x =</span> cyl, <span class="at">y =</span> mpg) <span class="sc">+</span></span>
<span id="cb24-3"><a href="#cb24-3" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb24-4"><a href="#cb24-4" tabindex="-1"></a> <span class="fu">theme_classic</span>()</span>
<span id="cb24-5"><a href="#cb24-5" tabindex="-1"></a>p</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-17-1.png" width="1050" /></p>
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" tabindex="-1"></a><span class="fu">library</span>(ggh4x)</span>
<span id="cb25-2"><a href="#cb25-2" tabindex="-1"></a>p <span class="sc">+</span></span>
<span id="cb25-3"><a href="#cb25-3" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(</span>
<span id="cb25-4"><a href="#cb25-4" tabindex="-1"></a> <span class="at">minor_breaks =</span> <span class="dv">16</span><span class="sc">:</span><span class="dv">32</span> <span class="sc">/</span> <span class="dv">4</span>,</span>
<span id="cb25-5"><a href="#cb25-5" tabindex="-1"></a> <span class="at">guide =</span> <span class="fu">guide_axis_minor</span>()</span>
<span id="cb25-6"><a href="#cb25-6" tabindex="-1"></a> ) <span class="sc">+</span></span>
<span id="cb25-7"><a href="#cb25-7" tabindex="-1"></a> <span class="co"># to control relative length of minor ticks</span></span>
<span id="cb25-8"><a href="#cb25-8" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">ggh4x.axis.ticks.length.minor =</span> <span class="fu">rel</span>(.<span class="dv">8</span>))</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-17-2.png" width="1050" /></p>
</div>
<div id="relations-imbriquées" class="section level3 hasAnchor">
<h3 class="hasAnchor">Relations imbriquées<a href="#relations-imbriquées" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>La fonction <code data-pkg="ggh4x">guide_axis_nested</code> de l’extension <code class="pkg">ggh4x</code> permet d’afficher sur un axe des relations imbriquées.</p>
<div class="sourceCode" id="cb26"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb26-1"><a href="#cb26-1" tabindex="-1"></a><span class="fu">library</span>(ggh4x)</span>
<span id="cb26-2"><a href="#cb26-2" tabindex="-1"></a>df <span class="ot"><-</span> <span class="fu">data.frame</span>(</span>
<span id="cb26-3"><a href="#cb26-3" tabindex="-1"></a> <span class="at">item =</span> <span class="fu">c</span>(<span class="st">"Coffee"</span>, <span class="st">"Tea"</span>, <span class="st">"Apple"</span>, <span class="st">"Pear"</span>, <span class="st">"Car"</span>),</span>
<span id="cb26-4"><a href="#cb26-4" tabindex="-1"></a> <span class="at">type =</span> <span class="fu">c</span>(<span class="st">"Drink"</span>, <span class="st">"Drink"</span>, <span class="st">"Fruit"</span>, <span class="st">"Fruit"</span>, <span class="st">""</span>),</span>
<span id="cb26-5"><a href="#cb26-5" tabindex="-1"></a> <span class="at">amount =</span> <span class="fu">c</span>(<span class="dv">5</span>, <span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">1</span>),</span>
<span id="cb26-6"><a href="#cb26-6" tabindex="-1"></a> <span class="at">stringsAsFactors =</span> <span class="cn">FALSE</span></span>
<span id="cb26-7"><a href="#cb26-7" tabindex="-1"></a>)</span>
<span id="cb26-8"><a href="#cb26-8" tabindex="-1"></a></span>
<span id="cb26-9"><a href="#cb26-9" tabindex="-1"></a><span class="fu">ggplot</span>(df) <span class="sc">+</span></span>
<span id="cb26-10"><a href="#cb26-10" tabindex="-1"></a> <span class="fu">aes</span>(<span class="at">x =</span> <span class="fu">interaction</span>(item, type), <span class="at">y =</span> amount) <span class="sc">+</span></span>
<span id="cb26-11"><a href="#cb26-11" tabindex="-1"></a> <span class="fu">geom_col</span>() <span class="sc">+</span></span>
<span id="cb26-12"><a href="#cb26-12" tabindex="-1"></a> <span class="fu">guides</span>(<span class="at">x =</span> <span class="fu">guide_axis_nested</span>())</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-18-1.png" width="1050" /></p>
</div>
<div id="combinaison-de-variables-sur-laxe-des-x" class="section level3 hasAnchor">
<h3 class="hasAnchor">Combinaison de variables sur l’axe des X<a href="#combinaison-de-variables-sur-laxe-des-x" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>L’extension <code class="upset">ggupset</code> fournie une fonction <code data-pkg="ggupset">scale_x_upset</code> permettant de représenter des combinaisons de variables sur l’axe des x, combinaisons de variables stockées sous forme d’une colonne de type liste. Pour plus d’informations, voir <a href="https://github.com/const-ae/ggupset" class="uri">https://github.com/const-ae/ggupset</a>.</p>
<div class="sourceCode" id="cb27"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb27-1"><a href="#cb27-1" tabindex="-1"></a><span class="fu">library</span>(ggupset)</span>
<span id="cb27-2"><a href="#cb27-2" tabindex="-1"></a><span class="fu">library</span>(tidyverse, <span class="at">quietly =</span> <span class="cn">TRUE</span>)</span>
<span id="cb27-3"><a href="#cb27-3" tabindex="-1"></a>tidy_movies <span class="sc">%>%</span></span>
<span id="cb27-4"><a href="#cb27-4" tabindex="-1"></a> <span class="fu">distinct</span>(title, year, length, <span class="at">.keep_all =</span> <span class="cn">TRUE</span>) <span class="sc">%>%</span></span>
<span id="cb27-5"><a href="#cb27-5" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> Genres)) <span class="sc">+</span></span>
<span id="cb27-6"><a href="#cb27-6" tabindex="-1"></a> <span class="fu">geom_bar</span>() <span class="sc">+</span></span>
<span id="cb27-7"><a href="#cb27-7" tabindex="-1"></a> <span class="fu">scale_x_upset</span>(<span class="at">n_intersections =</span> <span class="dv">20</span>)</span></code></pre></div>
<pre><code>Warning: Removed 100 rows containing non-finite values
(`stat_count()`).</code></pre>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-19-1.png" width="1050" /> ### Zoom sur un axe</p>
<p>L’extension <code class="pkg">ggforce</code> propose une fonction <code data-pkg="ggforce">facet_zoom</code> permettant de zoomer une partie d’un axe.</p>
<div class="sourceCode" id="cb29"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb29-1"><a href="#cb29-1" tabindex="-1"></a><span class="fu">library</span>(ggforce)</span>
<span id="cb29-2"><a href="#cb29-2" tabindex="-1"></a><span class="fu">ggplot</span>(iris, <span class="fu">aes</span>(Petal.Length, Petal.Width, <span class="at">colour =</span> Species)) <span class="sc">+</span></span>
<span id="cb29-3"><a href="#cb29-3" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb29-4"><a href="#cb29-4" tabindex="-1"></a> <span class="fu">facet_zoom</span>(<span class="at">x =</span> Species <span class="sc">==</span> <span class="st">"versicolor"</span>)</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-20-1.png" width="1050" /></p>
</div>
<div id="des-facettes-paginées-diviser-en-plusieurs-sous-graphiques" class="section level3 hasAnchor">
<h3 class="hasAnchor">Des facettes paginées (diviser en plusieurs sous-graphiques)<a href="#des-facettes-paginées-diviser-en-plusieurs-sous-graphiques" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>Les fonctions <code data-pkg="ggforce">facet_wrap_paginate</code> et <code data-pkg="ggforce">facet_grid_paginate</code> de <code class="pkg">ggforce</code> permet de découper facilement un graphique en facettes en plusieurs pages.</p>
<div class="sourceCode" id="cb30"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb30-1"><a href="#cb30-1" tabindex="-1"></a><span class="fu">ggplot</span>(diamonds) <span class="sc">+</span></span>
<span id="cb30-2"><a href="#cb30-2" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="fu">aes</span>(carat, price), <span class="at">alpha =</span> <span class="fl">0.1</span>) <span class="sc">+</span></span>
<span id="cb30-3"><a href="#cb30-3" tabindex="-1"></a> <span class="fu">facet_wrap_paginate</span>(<span class="sc">~</span> cut<span class="sc">:</span>clarity, <span class="at">ncol =</span> <span class="dv">3</span>, <span class="at">nrow =</span> <span class="dv">3</span>, <span class="at">page =</span> <span class="dv">1</span>)</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-21-1.png" width="1050" /></p>
<div class="sourceCode" id="cb31"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb31-1"><a href="#cb31-1" tabindex="-1"></a><span class="fu">ggplot</span>(diamonds) <span class="sc">+</span></span>
<span id="cb31-2"><a href="#cb31-2" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="fu">aes</span>(carat, price), <span class="at">alpha =</span> <span class="fl">0.1</span>) <span class="sc">+</span></span>
<span id="cb31-3"><a href="#cb31-3" tabindex="-1"></a> <span class="fu">facet_wrap_paginate</span>(<span class="sc">~</span> cut<span class="sc">:</span>clarity, <span class="at">ncol =</span> <span class="dv">3</span>, <span class="at">nrow =</span> <span class="dv">3</span>, <span class="at">page =</span> <span class="dv">2</span>)</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-21-2.png" width="1050" /></p>
<div class="sourceCode" id="cb32"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb32-1"><a href="#cb32-1" tabindex="-1"></a><span class="fu">ggplot</span>(diamonds) <span class="sc">+</span></span>
<span id="cb32-2"><a href="#cb32-2" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="fu">aes</span>(carat, price), <span class="at">alpha =</span> <span class="fl">0.1</span>) <span class="sc">+</span></span>
<span id="cb32-3"><a href="#cb32-3" tabindex="-1"></a> <span class="fu">facet_wrap_paginate</span>(<span class="sc">~</span> cut<span class="sc">:</span>clarity, <span class="at">ncol =</span> <span class="dv">3</span>, <span class="at">nrow =</span> <span class="dv">3</span>, <span class="at">page =</span> <span class="dv">3</span>)</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-21-3.png" width="1050" /></p>
</div>
</div>
<div id="cartes" class="section level2 hasAnchor">
<h2 class="hasAnchor">Cartes<a href="#cartes" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>Voir le <a href="cartes.html">chapitre dédié</a>.</p>
</div>
<div id="graphiques-complexes" class="section level2 hasAnchor">
<h2 class="hasAnchor">Graphiques complexes<a href="#graphiques-complexes" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<div id="graphiques-divergents" class="section level3 hasAnchor">
<h3 class="hasAnchor">Graphiques divergents<a href="#graphiques-divergents" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>L’extension <code>ggcharts</code> fournit plusieurs fonctions de haut niveau pour faciliter la réalisation de graphiques divergents en barres (<code data-pkg="ggcharts">diverging_bar_chart</code>), en sucettes (<code data-pkg="ggcharts">diverging_lollipop_chart</code>) voire même une pyramide des âges (<code data-pkg="ggcharts">pyramid_chart</code>).</p>
<div class="sourceCode" id="cb33"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb33-1"><a href="#cb33-1" tabindex="-1"></a><span class="fu">library</span>(ggcharts)</span>
<span id="cb33-2"><a href="#cb33-2" tabindex="-1"></a><span class="fu">data</span>(mtcars)</span>
<span id="cb33-3"><a href="#cb33-3" tabindex="-1"></a>mtcars_z <span class="ot"><-</span> dplyr<span class="sc">::</span><span class="fu">transmute</span>(</span>
<span id="cb33-4"><a href="#cb33-4" tabindex="-1"></a> <span class="at">.data =</span> mtcars,</span>
<span id="cb33-5"><a href="#cb33-5" tabindex="-1"></a> <span class="at">model =</span> <span class="fu">row.names</span>(mtcars),</span>
<span id="cb33-6"><a href="#cb33-6" tabindex="-1"></a> <span class="at">hpz =</span> <span class="fu">scale</span>(hp)</span>
<span id="cb33-7"><a href="#cb33-7" tabindex="-1"></a>)</span>
<span id="cb33-8"><a href="#cb33-8" tabindex="-1"></a></span>
<span id="cb33-9"><a href="#cb33-9" tabindex="-1"></a><span class="fu">diverging_bar_chart</span>(<span class="at">data =</span> mtcars_z, <span class="at">x =</span> model, <span class="at">y =</span> hpz)</span></code></pre></div>
<pre><code>Warning: Using one column matrices in `filter()` was deprecated in
dplyr 1.1.0.
ℹ Please use one dimensional logical vectors instead.
ℹ The deprecated feature was likely used in the dplyr
package.
Please report the issue at
<]8;;https://github.com/tidyverse/dplyr/issueshttps://github.com/tidyverse/dplyr/issues]8;;>.</code></pre>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-22-1.png" width="1050" /></p>
<div class="sourceCode" id="cb35"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb35-1"><a href="#cb35-1" tabindex="-1"></a><span class="fu">diverging_lollipop_chart</span>(</span>
<span id="cb35-2"><a href="#cb35-2" tabindex="-1"></a> <span class="at">data =</span> mtcars_z,</span>
<span id="cb35-3"><a href="#cb35-3" tabindex="-1"></a> <span class="at">x =</span> model,</span>
<span id="cb35-4"><a href="#cb35-4" tabindex="-1"></a> <span class="at">y =</span> hpz,</span>
<span id="cb35-5"><a href="#cb35-5" tabindex="-1"></a> <span class="at">lollipop_colors =</span> <span class="fu">c</span>(<span class="st">"#006400"</span>, <span class="st">"#b32134"</span>),</span>
<span id="cb35-6"><a href="#cb35-6" tabindex="-1"></a> <span class="at">text_color =</span> <span class="fu">c</span>(<span class="st">"#006400"</span>, <span class="st">"#b32134"</span>)</span>
<span id="cb35-7"><a href="#cb35-7" tabindex="-1"></a>)</span></code></pre></div>
<p><img src="graphs/etendre-ggplot2/unnamed-chunk-23-1.png" width="1050" /></p>
</div>
<div id="pyramides-des-âges" class="section level3 hasAnchor">
<h3 class="hasAnchor">Pyramides des âges<a href="#pyramides-des-âges" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>Plussieurs solutions sont disponible pour réaliser une <dfn>pyramide des âges</dfn>.</p>
<p>Tout d’abord, <code class="pkg">ggcharts</code> propose une fonction <code class="ggcharts">pyramid_chart</code>.</p>
<div class="sourceCode" id="cb36"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb36-1"><a href="#cb36-1" tabindex="-1"></a><span class="fu">library</span>(ggcharts)</span>
<span id="cb36-2"><a href="#cb36-2" tabindex="-1"></a><span class="fu">data</span>(<span class="st">"popch"</span>)</span>
<span id="cb36-3"><a href="#cb36-3" tabindex="-1"></a><span class="fu">pyramid_chart</span>(<span class="at">data =</span> popch, <span class="at">x =</span> age, <span class="at">y =</span> pop, <span class="at">group =</span> sex)</span></code></pre></div>