Introduction à R et représentation graphiques sous ggplot2
INRAE UMR EcoSys
1/4/24
| Organisation |
|---|
| Utilisation générale |
| Créer son projet |
| Importer des données |
Graphiques avec ggplot2 et `palmerpenguins |
tidyversepalmerpenguins# Générer des données simulées
fonction_data <- function(n1, n2, m1, m2, s1, s2) {
# n1: taille d'échantillon contôle
# n2: taille d'échantillon traité
# m1: moyenne échantillon contôle
# m2: moyenne échantillon traité
# s1: écart type échantillon contôle
# s2: écart type échantillon traité
ctrl <- rnorm(n1, m1, s1) # Simuler échantillon contôle
trt <- rnorm(n2, m2, s2) # Simuler échantillon traité
df <- data.frame(Trt = c(rep("Ctrl", n1),
rep("Trt", n2)),
Activity = c(ctrl, trt)) # Stocker les données
return(df)
}
dsim <- fonction_data(50, 50, 50, 30, 5, 3) # Appeler la fonction
hist(dsim$Activity) # Visualiserread.csv() ou read.table()data_virg & data_tabTreatment avec df$post-treatment avec df[,]post-treatment avec filterboxplot()write.csv()path = "data/data-clean/data_clean.csv"ggplot2 et palmerpenguins

ggplot| Elément/Fonction | Explication |
|---|---|
ggplot() |
Fonction principale |
aes() |
aesthetics: contrôle les éléments du graphique (x, y, colour, fill, shape, size) |
geom_() |
Contrôle les éléments graphiques (points, boxplot, density, … ) |
theme() |
Customization de l’apparence du graphique |
ggplotggplotAstuces
NA ?ggplot2 cheatsheetTutoriels - Data Science avec R - R Cookbook - Quick-R
Galleries - R Graphics Gallery
Livres - The R Book - Statistical Rethinking
Cours - Lectures Statistical Rethinking - eLearning INRAE
Débuggage - Stack Overflow - R-help
