forked from MTES-MCT/parcours_r_module_datavisualisation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09-la-mise-en-page-de-plusieurs-graphiques.Rmd
60 lines (47 loc) · 1.88 KB
/
09-la-mise-en-page-de-plusieurs-graphiques.Rmd
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
# La mise en page de plusieurs graphiques
Le package `cowplot` permet la combinaison de plusieurs graphiques. Il est composé de plusieurs fonctions.
- le fonction **plot_grid** qui permet de disposer ***n*** graphes sur ***i*** colonnes et ***j*** lignes
```{r fg9_1, echo=T,eval=T,fig.height=3.5}
gg1<-ggplot(graphique1) +
geom_point(aes(x=Gross_Domestic_Product_GDP,
y=Maternal_mortality_ratio))+
scale_x_log10()+
scale_y_log10()+
labs(title="Mortalité maternelle en fonction du PIB par habitant",
subtitle="En 2015",
x="PIB",
y="Taux de mortalité de la mère \n(pour 100 000 naissances)",
caption="Source : ODD / ONU") +
theme(axis.title= element_text(size=9))
gg2<-ggplot(graphique1) +
geom_density(aes(x=log(Gross_Domestic_Product_GDP))
)
plot_grid(gg1,gg2, ncol = 1, nrow = 2)
```
- le fonction **draw_plot** associée à **ggdraw** qui permet de disposer les graphiques à des places spécifiques
`ggdraw` initialise le graphique
```{r fg9_2, echo=T,eval=T,fig.height=3.5}
gg1<-ggplot(graphique1) +
geom_point(aes(x=Gross_Domestic_Product_GDP,
y=Maternal_mortality_ratio))+
scale_x_log10()+
scale_y_log10()+
labs(title="Mortalité maternelle en fonction du PIB par habitant",
subtitle="En 2015",
x="PIB",
y="Taux de mortalité de la mère \n(pour 100 000 naissances)",
caption="Source : ODD / ONU") +
theme(axis.title= element_text(size=9))
gg2<-ggplot(graphique1) +
geom_density(aes(x=log(Gross_Domestic_Product_GDP)) )+
labs(x="Log(PIB)",
y="Densité")
gg3<-ggplot(data = graphique1) +
geom_bar(aes(x=Continent,fill=Continent))+
theme(axis.title.x = element_blank(),
axis.text.x = element_blank())
ggdraw() +
draw_plot(gg1, x=0, y=.5, width=1, height=.5) +
draw_plot(gg2, x=0, y=0, width=.3, height=.5) +
draw_plot(gg3, x=0.3, y=0, width=0.7, height=.5)
```