@@ -0,0 +1,4 @@ | |||
.Rproj.user | |||
.Rhistory | |||
.RData | |||
.Ruserdata |
@@ -0,0 +1,408 @@ | |||
--- | |||
title: "Chapitre 1" | |||
author: "Antoine Neuraz" | |||
date: "5/28/2019" | |||
output: html_document | |||
--- | |||
# Intro | |||
```{r , include=FALSE} | |||
knitr::opts_chunk$set(echo = FALSE) | |||
``` | |||
```{r, include=FALSE} | |||
library(ggplot2) | |||
library(tidyverse) | |||
library(see) | |||
library(patchwork) | |||
source('R/util_functions.R') | |||
seed = 44 | |||
my_theme_void <- function(base_size = 11, | |||
base_family = "", | |||
base_line_size = base_size / 170, | |||
base_rect_size = base_size / 170) { | |||
theme_void(base_size = base_size, | |||
base_family = base_family, | |||
base_line_size = base_line_size) %+replace% | |||
theme( legend.position = "none", | |||
plot.title = element_text(hjust = 0.5) | |||
) | |||
} | |||
``` | |||
```{r} | |||
size <- 100 | |||
min_x <- 0 | |||
max_x <- 1 | |||
outliers <- 2 | |||
p_color <- generate_uniform_dataset( | |||
dataset_size = size, | |||
min_x = min_x, | |||
max_x = max_x, | |||
outliers = outliers, | |||
seed = seed | |||
) %>% | |||
ggplot( | |||
data = ., | |||
aes( | |||
x = x, | |||
y = y, | |||
color = group | |||
) | |||
) + | |||
geom_point(size = 3) + | |||
scale_color_material_d() + | |||
my_theme_void() + | |||
labs(subtitle= "Couleur") | |||
#p_color | |||
``` | |||
```{r} | |||
p_angle <- generate_uniform_dataset( | |||
dataset_size = size, | |||
min_x = min_x, | |||
max_x = max_x, | |||
outliers = outliers, | |||
seed = seed | |||
) %>% | |||
mutate(angle = ifelse(group == "group1", 0, pi / 3)) %>% | |||
ggplot( | |||
data = ., | |||
aes( | |||
x = x, | |||
y = y, | |||
angle = angle | |||
) | |||
) + | |||
geom_spoke( | |||
radius = 0.04, | |||
size = .8 | |||
) + | |||
my_theme_void() + | |||
scale_color_material_d() + | |||
ggtitle("Angle") | |||
#p_angle | |||
``` | |||
```{r} | |||
p_size <- generate_uniform_dataset( | |||
dataset_size = size, | |||
min_x = min_x, | |||
max_x = max_x, | |||
outliers = outliers, | |||
seed = seed | |||
) %>% | |||
mutate(size = ifelse(group == "group1", 2, 3)) %>% | |||
ggplot( | |||
data = ., | |||
aes( | |||
x = x, | |||
y = y, | |||
size = size | |||
) | |||
) + | |||
geom_point() + | |||
my_theme_void() + | |||
scale_size(range = c(1, 3)) + | |||
ggtitle("Taille") | |||
#p_size | |||
``` | |||
```{r} | |||
p_grey <- generate_uniform_dataset( | |||
dataset_size = size, | |||
min_x = min_x, | |||
max_x = max_x, | |||
outliers = outliers, | |||
seed = seed | |||
) %>% | |||
ggplot( | |||
data = ., | |||
aes( | |||
x = x, | |||
y = y, | |||
color = group | |||
) | |||
) + | |||
geom_point(size = 3) + | |||
my_theme_void() + | |||
scale_color_manual(values = c('group2' = 'black', 'group1' = 'lightgrey')) + | |||
ggtitle("Luminosité") | |||
#p_grey | |||
``` | |||
```{r} | |||
dt <- generate_uniform_dataset( | |||
dataset_size = size, | |||
min_x = min_x, | |||
max_x = max_x, | |||
outliers = outliers, | |||
seed = seed | |||
) %>% | |||
mutate(curvature = ifelse(group == "group1", 0, 1)) | |||
p_curve <- dt %>% | |||
ggplot( | |||
data = ., | |||
aes( | |||
x = x, | |||
y = y, | |||
xend = x, | |||
yend = y+max_x/10, | |||
curvature = curvature | |||
) | |||
) + | |||
geom_curve(data = subset(dt, group == 'group1'), curvature = 0) + | |||
geom_curve(data = subset(dt, group == 'group2'), curvature = .7) + | |||
scale_color_material_d() + | |||
my_theme_void() + | |||
ggtitle("Courbe") | |||
#p_curve | |||
``` | |||
```{r} | |||
dt <- generate_uniform_dataset( | |||
dataset_size = size, | |||
min_x = min_x, | |||
max_x = max_x, | |||
outliers = outliers, | |||
seed = seed | |||
) | |||
p_box <- dt %>% | |||
ggplot( | |||
data = ., | |||
aes( | |||
x = x, | |||
xend = x+max_x/50, | |||
y = y, | |||
yend = y | |||
) | |||
) + | |||
geom_point(data = subset(dt, group=='group2'),aes(x = x+max_x/100), shape = 22, size = 4) + | |||
geom_segment() + | |||
#geom_curve(data = subset(dt, group == 'group2'), curvature = .7) + | |||
scale_color_material_d() + | |||
my_theme_void() + | |||
ggtitle("Encapsulage") | |||
#p_box | |||
``` | |||
```{r} | |||
p_shape <- generate_uniform_dataset( | |||
dataset_size = size, | |||
min_x = min_x, | |||
max_x = max_x, | |||
outliers = outliers, | |||
seed = seed | |||
) %>% | |||
ggplot( | |||
data = ., | |||
aes( | |||
x = x, | |||
y = y, | |||
shape = group | |||
) | |||
) + | |||
geom_point(size = 3) + | |||
#scale_color_manual(values = c('group2' = 'black', 'group1' = 'lightgrey')) + | |||
my_theme_void() + | |||
ggtitle("Forme") | |||
#p_shape | |||
``` | |||
```{r} | |||
p_fill <- generate_uniform_dataset( | |||
dataset_size = size, | |||
min_x = min_x, | |||
max_x = max_x, | |||
outliers = outliers, | |||
seed = seed | |||
) %>% | |||
ggplot( | |||
data = ., | |||
aes( | |||
x = x, | |||
y = y, | |||
fill = group | |||
) | |||
) + | |||
geom_point(size = 3, shape = 21) + | |||
scale_fill_manual(values = c('group2' = 'black', 'group1' = 'white')) + | |||
my_theme_void() + | |||
ggtitle("Remplissage") | |||
#p_fill | |||
``` | |||
```{r encode, fig.height=12, fig.cap='Exemples d\'encodage', fig.align='center'} | |||
p_color + p_angle + | |||
p_size + p_grey + | |||
p_curve + p_box + | |||
p_shape + p_fill + | |||
plot_layout(ncol = 2) | |||
``` | |||
## Mappings in ggplot | |||
```{r} | |||
#theme_set(theme_void_real()) | |||
aes_pos <- ggplot() + | |||
geom_segment(data = data.frame(x = c(0, 0.5), | |||
xend = c(1, 0.5), | |||
y = c(0.5, 0), | |||
yend = c(0.5, 1)), | |||
aes(x = x, y = y, xend = xend, yend = yend), | |||
arrow = arrow(length = grid::unit(12, "pt")), size = .75) + | |||
annotate("text", .5, 1, size = 8, vjust = 1, hjust = 2.5, label = "y") + | |||
annotate("text", 1, .5, size = 8, vjust = 2, hjust = 1, label = "x") + | |||
theme_void() + theme(legend.position = 'none') + | |||
coord_cartesian(xlim = c(-.2, 1.2), ylim = c(-.2, 1.2)) + | |||
labs(title = 'position') | |||
aes_color <- ggplot() + | |||
geom_tile(data = data.frame(x = 0.15 + .2333*(0:3)), | |||
aes(x, y = .5, fill = factor(x)), width = .2, height = .6) + | |||
theme_void() + theme(legend.position = 'none') + | |||
scale_fill_viridis_d() + | |||
labs(title = 'couleur') | |||
aes_shape <- ggplot() + | |||
geom_point(data = data.frame(x = (.5 + 0:3)/4), | |||
aes(x, y = .5, shape = factor(x)), size = 8, fill = "grey80") + | |||
theme_void() + theme(legend.position = 'none') + | |||
scale_shape_manual(values = 21:24) + | |||
expand_limits(x=c(0,1)) + | |||
labs(title = 'forme') | |||
aes_size <- ggplot() + | |||
geom_point(data = data.frame(x = (.5 + 0:3)/4), | |||
aes(x, y = .5, size = factor(x)), shape = 21, fill = "grey80") + | |||
theme_void() + theme(legend.position = 'none') + | |||
scale_size_manual(values = c(2, 5, 8, 11)) + | |||
expand_limits(x=c(0,1)) + | |||
labs(title = 'taille') | |||
aes_lwd <- ggplot() + | |||
geom_segment(data = data.frame(x = rep(0.05, 4), | |||
xend = rep(0.95, 4), | |||
y = (1.5 + 0:3)/6, | |||
yend = (1.5 + 0:3)/6, | |||
size = 4:1), | |||
aes(x = x, y = y, xend = xend, yend = yend, size = size)) + | |||
theme_void() + theme(legend.position = 'none') + | |||
scale_size_identity() + | |||
labs(title = 'épaisseur de ligne') | |||
aes_ltp <- ggplot() + | |||
geom_segment(data = data.frame(x = rep(0.05, 4), | |||
xend = rep(0.95, 4), | |||
y = (1.5 + 0:3)/6, | |||
yend = (1.5 + 0:3)/6, | |||
linetype = 4:1), | |||
aes(x = x, y = y, xend = xend, yend = yend, linetype = linetype), size = 1) + | |||
theme_void() + theme(legend.position = 'none') + | |||
scale_linetype_identity() + | |||
labs(title = 'type de ligne') | |||
aes_pos + aes_shape + aes_size + aes_color + aes_lwd + aes_ltp +plot_layout(nrow=2) | |||
``` | |||
figure from [https://serialmentor.com/dataviz/aesthetic-mapping.html]() | |||
## scales in ggplot | |||
```{r, fig.asp = .2} | |||
df <- data.frame(x = c(1:4)) | |||
scale_num <- ggplot(df, aes(x)) + | |||
geom_point(size = 3, color = "#0072B2", y = 1) + | |||
scale_y_continuous(limits = c(0.8, 1.2), expand = c(0, 0), breaks = 1, label = "position ") + | |||
scale_x_continuous(limits = c(.7, 4.4), breaks = 1:5, labels = c("1", "2", "3", "4", "5"), name = NULL, position = "top") + | |||
theme_minimal_grid() + | |||
theme(axis.ticks.length = grid::unit(0, "pt"), | |||
axis.text = element_text(size = 14), | |||
axis.title.y = element_blank(), | |||
axis.ticks.y = element_blank()) | |||
scale_color <- ggplot(df, aes(x, color = factor(x), fill = factor(x))) + | |||
geom_point(size = 5, shape = 22, y = 1) + | |||
scale_y_continuous(limits = c(0.8, 1.2), expand = c(0, 0), breaks = 1, label = "color ") + | |||
scale_x_continuous(limits = c(.7, 4.4), breaks = NULL) + | |||
scale_color_manual(values = c("#0082A6", "#4EBBB9", "#9CDFC2", "#D8F0CD"), guide = "none") + | |||
scale_fill_manual(values = c("#0082A6", "#4EBBB9", "#9CDFC2", "#D8F0CD"), guide = "none") + | |||
theme_minimal() + | |||
theme(axis.ticks.length = grid::unit(0, "pt"), | |||
axis.text.x = element_blank(), | |||
axis.text.y = element_text(size = 14), | |||
axis.title = element_blank(), | |||
axis.ticks = element_blank(), | |||
panel.grid.major = element_blank()) | |||
scale_shape <- ggplot(df, aes(x, shape = factor(x))) + | |||
geom_point(size = 4, color = "grey30", y = 1, fill = "grey80") + | |||
scale_y_continuous(limits = c(0.8, 1.2), expand = c(0, 0), breaks = 1, label = "shape ") + | |||
scale_x_continuous(limits = c(.7, 4.4), breaks = NULL) + | |||
scale_shape_manual(values = 21:24, guide = "none") + | |||
theme_minimal() + | |||
theme(axis.ticks.length = grid::unit(0, "pt"), | |||
axis.text.x = element_blank(), | |||
axis.text.y = element_text(size = 14), | |||
axis.title = element_blank(), | |||
axis.ticks = element_blank(), | |||
panel.grid.major = element_blank()) | |||
scale_num + scale_shape + scale_color + plot_layout(ncol = 1) | |||
``` | |||
figure from [https://serialmentor.com/dataviz/aesthetic-mapping.html]() | |||
```{r} | |||
dt <- data.frame(x = rep(1:5, 3), | |||
y = c(rep(1,5), rep(2,5),rep(3,5)), | |||
group = rep(1, 5*3)) | |||
dt$group[8] <- 2 | |||
ggplot(data = dt, | |||
mapping = aes(x = x, y = y, fill = as.factor(group))) + | |||
geom_tile(color = 'white', size = 2) + | |||
annotate("segment", x=0.2,xend=5,y=3.8,yend=3.8,arrow=arrow(type="closed",length= unit(.4,"cm"))) + | |||
annotate("segment", x=0.2,xend=0.2,y=3.8,yend=1,arrow=arrow(type="closed",length= unit(.4,"cm"))) + | |||
annotate("text", x=3, y=0, label = "Cellule contenant une valeur",hjust=0.5) + | |||
annotate("segment", x=3,xend=3,y=0.2,yend=1.5,arrow=arrow(type="closed", length= unit(.4,"cm"))) + | |||
scale_fill_manual(values = list("lightgrey", "darkred"))+ | |||
scale_x_continuous(position = "top")+ | |||
xlab('Attributs (colonnes)') + | |||
ylab('Items (lignes)') + | |||
theme_modern() + | |||
theme(legend.position = 'none', | |||
axis.text=element_blank(), | |||
axis.line =element_blank()) | |||
``` | |||
@@ -0,0 +1,191 @@ | |||
--- | |||
title: "ggplot2 avancé" | |||
author: "Antoine Neuraz" | |||
date: "6/5/2019" | |||
output: html_document | |||
--- | |||
# `ggplot2` : techniques avancées | |||
```{r, include=FALSE} | |||
knitr::opts_chunk$set(echo = TRUE, | |||
fig.pos = "center") | |||
library(tidyverse) | |||
library(ggplot2) | |||
library(see) | |||
library(patchwork) | |||
source('R/util_functions.R') | |||
``` | |||
## Créer son propre thème `ggplot2` | |||
Les thèmes de `ggplot2` permettent de contrôler l'apparence des plots. Il est possible de modifier un thème standard en utilisant la fonction `theme()`. Mais nous allons voir ici comment créer un thème personalisé. | |||
Il est bien entendu possible de créer un thème de toutes pièces. Pour cela, il faut définir un à un tous les éléments possibles du thème mais c'est très long et rébarbatif. Dans `ggplot2`, le seul thème défini de cette façon est le thème de base `theme_grey()` (voir le [repo officiel](https://github.com/tidyverse/ggplot2/blob/master/R/theme-defaults.r)). | |||
Les autres thèmes héritent les attribut de ce premier thème et modifient uniquement éléments nécéssaires. Par exemple, `theme_bw()` est construit à partir de `theme_grey()` et `theme_minimal()` se base sur `theme_bw()`. C'est beaucoup plus pratique de définir les thèmes de cette façon. | |||
### un thème est une fonction | |||
Un thème est une fonction R classique qui prend comme arguments 4 variables : | |||
- base_size : taille de base du texte (défaut = 11) | |||
- base_family : famille de polices de base (défaut = "") | |||
- base_line_size : taille de base des éléments `line` (défaut = base_size / 22 ) | |||
- base_rect_size : taille de base des éléments `rect` (défault = base_size / 22 ) | |||
```{r, eval = FALSE} | |||
my_theme <- function(base_size = 11, | |||
base_family = "", | |||
base_line_size = base_size / 22, | |||
base_rect_size = base_size / 22) {} | |||
``` | |||
### modifier un thème de base avec `%+replace%` | |||
Ensuite, nous allons choisir un thème de base duquel notre thème personalisé va hériter les éléments par défaut. En effet, tous les éléments que nous ne spécifieront pas seront basés sur le thème de base. Par exemple, nous pouvons choisir `theme_minimal()`. | |||
Pour modifier les éléments du thème de base, il faut utiliser l'opérateur `%+replace%` suivi de la fonction `theme()`. C'est dans cette dernière que nous pourrons spécifier les différents éléments à modifier par rapport au thème de base. | |||
```{r, eval = FALSE} | |||
my_theme <- function(base_size = 11, | |||
base_family = "", | |||
base_line_size = base_size / 22, | |||
base_rect_size = base_size / 22) { | |||
theme_minimal(base_size = base_size, | |||
base_family = base_family, | |||
base_line_size = base_line_size, | |||
base_rect_size = base_rect_size) %+replace% | |||
theme( | |||
# éléments à modifier | |||
) | |||
} | |||
``` | |||
### définir de nouveaux attributs | |||
Nous pouvons a présent inserer dans la fonction thème les éléments à modifier. Notez qu'il ne faut pas utiliser de tailles absolues mais définir des tailles relatives avec la fonction `rel()`. | |||
#### `my_theme()` {-} | |||
Voici un exemple de thème personnalisé (très fortement inspiré du thème `theme_modern()` du package `see`) basé sur `theme_minimal()` : | |||
```{r, eval = TRUE} | |||
my_theme <- function(base_size = 11, | |||
base_family = "", | |||
base_line_size = base_size / 22, | |||
base_rect_size = base_size / 22) { | |||
half_line <- base_size/2 | |||
theme_minimal(base_size = base_size, | |||
base_family = base_family, | |||
base_line_size = base_line_size, | |||
base_rect_size = base_rect_size) %+replace% | |||
theme( | |||
## Panel grid ## | |||
panel.border = element_blank(), | |||
panel.grid.major = element_blank(), | |||
panel.grid.minor = element_blank(), | |||
## Title ## | |||
plot.title = element_text(size = rel(1.3), | |||
face = "plain", margin = margin(0, 0, 20, 0)), | |||
## Axis ## | |||
axis.line = element_line(colour = "black", size = rel(0.5)), | |||
axis.title.y = element_text(margin = margin(t = 0, r = rel(20), b = 0, l = 0), | |||
angle = 90), | |||
axis.title.x = element_text(margin = margin(t = rel(20), r = 0, b = 0, l = 0)), | |||
axis.title = element_text(size = rel(1.2), | |||
face = "plain"), | |||
axis.text = element_text(size = rel(.8)), | |||
axis.ticks = element_blank(), | |||
## Legend ## | |||
legend.key = element_blank(), | |||
legend.position = "bottom", | |||
legend.text = element_text(size = rel(1.1)), | |||
legend.title = element_text(size = rel(1.1)), | |||
legend.spacing.x = unit(2, "pt"), | |||
## Background ## | |||
strip.background = element_blank(), | |||
plot.tag = element_text(size = rel(1.3), face = "bold"), | |||
strip.text = element_text(face = "bold") | |||
) | |||
} | |||
``` | |||
#### `my_theme_dark()` {-} | |||
Et un thème sombre basé sur `my_theme()` et très fortement inspiré de `theme_blackboard()` du package `see` : | |||
```{r} | |||
my_theme_dark <-function(base_size = 11, | |||
base_family = "", | |||
base_line_size = base_size / 22, | |||
base_rect_size = base_size / 22) { | |||
dark_color = "#0d0d0d" | |||
light_color = "#E0E0E0" | |||
my_theme(base_size = base_size, | |||
base_family = base_family, | |||
base_line_size = base_line_size, | |||
base_rect_size = base_rect_size) %+replace% | |||
theme( | |||
## Backgrounds ## | |||
plot.background = element_rect(fill = dark_color), | |||
panel.background = element_rect(fill = dark_color, color=dark_color), | |||
legend.background = element_rect(fill = dark_color, color=dark_color), | |||
## Lines ## | |||
axis.line = element_line(color = light_color), | |||
## Text ## | |||
text = element_text(family = base_family, face = "plain", | |||
color = light_color, size = base_size, | |||
hjust = 0.5, vjust = 0.5, angle = 0, | |||
lineheight =0.9, margin = margin(), | |||
debug = FALSE), | |||
axis.text = element_text(color = light_color) | |||
) | |||
} | |||
``` | |||
### Exemple | |||
Créons un plot d'exemple à partir d'un jeu de données synthétique | |||
```{r, echo=TRUE} | |||
p <- generate_uniform_dataset( | |||
dataset_size = 100, | |||
min_x = 0, max_x = 1, | |||
outliers = 2, seed = 506 | |||
) %>% | |||
ggplot(data = ., aes( x = x, y = y, color = group)) + | |||
geom_point(size = 3) + | |||
scale_color_material_d() + | |||
labs(title= "theme_minimal()", | |||
x="legende axe x", | |||
y="legende axe y") | |||
``` | |||
```{r, echo=TRUE} | |||
p | |||
``` | |||
```{r, echo=TRUE} | |||
p + theme_minimal() | |||
``` | |||
```{r, echo=TRUE} | |||
p + my_theme() | |||
``` | |||
```{r,echo=TRUE} | |||
p + my_theme_dark() | |||
``` |
@@ -0,0 +1,3 @@ | |||
`r if (knitr::is_html_output()) ' | |||
# References {-} | |||
'` |
@@ -0,0 +1,65 @@ | |||
generate_uniform_dataset <- function( | |||
dataset_size = 20, | |||
min_x = 0, | |||
max_x = 5, | |||
outliers = 2, | |||
seed = NULL) { | |||
set.seed(seed) | |||
dt <- data.frame( | |||
x = round(runif(dataset_size, min = min_x, max = max_x), 2), | |||
y = round(runif(dataset_size, min = min_x, max = max_x), 2), | |||
group = "group1", | |||
stringsAsFactors = F | |||
) | |||
dt$group[sample(1:dataset_size, outliers)] <- "group2" | |||
dt | |||
} | |||
make_oscillate <- function(dt, group_sel, size) { | |||
dt <- dt %>% | |||
mutate( | |||
oscillate = ifelse(group == group_sel, 0, size), | |||
time = 1 | |||
) | |||
dt1 <- dt %>% | |||
mutate( | |||
y = y + oscillate, | |||
time = 2 | |||
) | |||
dt2 <- dt %>% | |||
mutate( | |||
y = y, | |||
time = 3 | |||
) | |||
dt3 <- dt %>% | |||
mutate( | |||
y = y - oscillate, | |||
time = 4 | |||
) | |||
bind_rows(dt, dt1, dt2, dt3) | |||
} | |||
theme_minimal_grid <- function(base_size = 11, | |||
base_family = "", | |||
base_line_size = base_size / 22, | |||
base_rect_size = base_size / 22) { | |||
half_line <- base_size / 2 | |||
theme_minimal(base_size = base_size, | |||
base_family = base_family, | |||
base_line_size = base_line_size, | |||
base_rect_size = base_rect_size) %+replace% | |||
theme( | |||
plot.margin = margin(half_line/2, 1.5, half_line/2, 1.5), | |||
complete = TRUE | |||
) | |||
} |
@@ -0,0 +1 @@ | |||
This is a minimal example of a book based on R Markdown and **bookdown** (https://github.com/rstudio/bookdown). Please see the page "Get Started" at https://bookdown.org/ for how to compile this example. |
@@ -0,0 +1,5 @@ | |||
book_filename: "dataviz" | |||
delete_merged_file: true | |||
language: | |||
ui: | |||
chapter_name: "Chaptire " |
@@ -0,0 +1,17 @@ | |||
bookdown::gitbook: | |||
css: style.css | |||
config: | |||
toc: | |||
before: | | |||
<li><a href="./">A Minimal Book Example</a></li> | |||
after: | | |||
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li> | |||
download: ["pdf", "epub"] | |||
bookdown::pdf_book: | |||
includes: | |||
in_header: preamble.tex | |||
latex_engine: xelatex | |||
citation_package: natbib | |||
keep_tex: yes | |||
bookdown::epub_book: default | |||
@@ -0,0 +1,10 @@ | |||
@Book{xie2015, | |||
title = {Dynamic Documents with {R} and knitr}, | |||
author = {Yihui Xie}, | |||
publisher = {Chapman and Hall/CRC}, | |||
address = {Boca Raton, Florida}, | |||
year = {2015}, | |||
edition = {2nd}, | |||
note = {ISBN 978-1498716963}, | |||
url = {http://yihui.name/knitr/}, | |||
} |
@@ -0,0 +1,57 @@ | |||
--- | |||
title: "Visualisation de données avec R" | |||
author: "Antoine Neuraz" | |||
date: "`r Sys.Date()`" | |||
site: bookdown::bookdown_site | |||
documentclass: book | |||
bibliography: [book.bib, packages.bib] | |||
biblio-style: apalike | |||
link-citations: yes | |||
description: "Cours introductif à la visualisation de données avec R. Ce cours a pour but d introduire les concepts théoriques de base en visualisation ainsi que des exemples concrets." | |||
--- | |||
Cours introductif à la visualisation de données avec R. Ce cours a pour but d introduire les concepts théoriques de base en visualisation ainsi que des exemples concrets. | |||
# Prerequis {-} | |||
Pour les parties théoriques, aucun prérequis n'est nécessaire. Les exemples pratiques sont conçus avec le logiciel R et le package `ggplot2` | |||
## Installer R {-} | |||
Vous devez avoir installé le logiciel R pour pouvoir suivre les exemples pratiques. | |||
Vous trouverez les liens de téléchargement ici : [https://cran.r-project.org]() | |||
## Installer RStudio (facultatif) {-} | |||
Nous conseillons également d'installer l'interface de développement (IDE) RStudio qui vous facilitera les choses pour la prévisualisation des contenus et des rendus. Bien entendu, si vous avez déjà une IDE préférée, vous pouvez continuer à l'utiliser. Vous trouverez la RStudio Desktop en version open source (gratuite) ici : [https://www.rstudio.com/products/rstudio/#Desktop]() | |||
## Installer les packages nécessaires {-} | |||
Dans ce cours, un certain nombre de packages sont utilisés très fréquement et doivent être installés : | |||
```{r } | |||
pkg_list_req = c("tidyverse", | |||
"ggplot2", | |||
"see") | |||
``` | |||
```{r, eval=FALSE} | |||
install.packages(pkg_list_req) | |||
``` | |||
Un certain nombre d'autres packages, utilisés plus ponctuellement vous seront indiqués dans les différents chapitres. Voici une liste exhaustive des packages utilisés dans ce cours : | |||
```{r include=FALSE} | |||
# automatically create a bib database for R packages | |||
pkg_list = c(pkg_list_req) | |||
knitr::write_bib(c( | |||
.packages(), pkg_list | |||
), 'packages.bib') | |||
``` | |||
`r pkg_list` |
@@ -0,0 +1,86 @@ | |||
@Manual{R-base, | |||
title = {R: A Language and Environment for Statistical Computing}, | |||
author = {{R Core Team}}, | |||
organization = {R Foundation for Statistical Computing}, | |||
address = {Vienna, Austria}, | |||
year = {2018}, | |||
url = {https://www.R-project.org/}, | |||
} | |||
@Manual{R-dplyr, | |||
title = {dplyr: A Grammar of Data Manipulation}, | |||
author = {Hadley Wickham and Romain François and Lionel Henry and Kirill Müller}, | |||
year = {2019}, | |||
note = {R package version 0.8.0.1}, | |||
url = {https://CRAN.R-project.org/package=dplyr}, | |||
} | |||
@Manual{R-forcats, | |||
title = {forcats: Tools for Working with Categorical Variables (Factors)}, | |||
author = {Hadley Wickham}, | |||
year = {2018}, | |||
note = {R package version 0.3.0}, | |||
url = {https://CRAN.R-project.org/package=forcats}, | |||
} | |||
@Manual{R-ggplot2, | |||
title = {ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics}, | |||
author = {Hadley Wickham and Winston Chang and Lionel Henry and Thomas Lin Pedersen and Kohske Takahashi and Claus Wilke and Kara Woo}, | |||
year = {2019}, | |||
note = {R package version 3.1.1}, | |||
url = {https://CRAN.R-project.org/package=ggplot2}, | |||
} | |||
@Manual{R-patchwork, | |||
title = {patchwork: The Composer of ggplots}, | |||
author = {Thomas Lin Pedersen}, | |||
year = {2017}, | |||
note = {R package version 0.0.1}, | |||
url = {https://github.com/thomasp85/patchwork}, | |||
} | |||
@Manual{R-purrr, | |||
title = {purrr: Functional Programming Tools}, | |||
author = {Lionel Henry and Hadley Wickham}, | |||
year = {2019}, | |||
note = {R package version 0.3.2}, | |||
url = {https://CRAN.R-project.org/package=purrr}, | |||
} | |||
@Manual{R-readr, | |||
title = {readr: Read Rectangular Text Data}, | |||
author = {Hadley Wickham and Jim Hester and Romain Francois}, | |||
year = {2018}, | |||
note = {R package version 1.3.1}, | |||
url = {https://CRAN.R-project.org/package=readr}, | |||
} | |||
@Manual{R-see, | |||
title = {see: Visualisation Toolbox for 'easystats' and Extra Geoms, Themes | |||
and Color Palettes for 'ggplot2'}, | |||
author = {Daniel Lüdecke and Dominique Makowski and Philip Waggoner and Mattan S. Ben-Shachar}, | |||
year = {2019}, | |||
note = {R package version 0.1.0}, | |||
url = {https://CRAN.R-project.org/package=see}, | |||
} | |||
@Manual{R-stringr, | |||
title = {stringr: Simple, Consistent Wrappers for Common String Operations}, | |||
author = {Hadley Wickham}, | |||
year = {2019}, | |||
note = {R package version 1.4.0}, | |||
url = {https://CRAN.R-project.org/package=stringr}, | |||
} | |||
@Manual{R-tibble, | |||
title = {tibble: Simple Data Frames}, | |||
author = {Kirill Müller and Hadley Wickham}, | |||
year = {2019}, | |||
note = {R package version 2.1.1}, | |||
url = {https://CRAN.R-project.org/package=tibble}, | |||
} | |||
@Manual{R-tidyr, | |||
title = {tidyr: Easily Tidy Data with 'spread()' and 'gather()' Functions}, | |||
author = {Hadley Wickham and Lionel Henry}, | |||
year = {2019}, | |||
note = {R package version 0.8.3}, | |||
url = {https://CRAN.R-project.org/package=tidyr}, | |||
} | |||
@Manual{R-tidyverse, | |||
title = {tidyverse: Easily Install and Load the 'Tidyverse'}, | |||
author = {Hadley Wickham}, | |||
year = {2017}, | |||
note = {R package version 1.2.1}, | |||
url = {https://CRAN.R-project.org/package=tidyverse}, | |||
} |
@@ -0,0 +1 @@ | |||
\usepackage{booktabs} |
@@ -0,0 +1,14 @@ | |||
p.caption { | |||
color: #777; | |||
margin-top: 10px; | |||
} | |||
p code { | |||
white-space: inherit; | |||
} | |||
pre { | |||
word-break: normal; | |||
word-wrap: normal; | |||
} | |||
pre code { | |||
white-space: inherit; | |||
} |