Nom : Terras

Prénom : Omar

Numéro étudiant :22309268

Question 1

{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)

Définition de la fonction demandée

f22309268 <- function(labelx = “x”, titre = “Analyse bivariée des données”, labely = “y”, typevar2, var1, var2) {

# Création du data frame pour ggplot df_temp <- data.frame(v1 = var1, v2 = var2)

# Initialisation du graphique p <- ggplot(df_temp)

# Choix du graphique selon le type de variable[cite: 5] if (typevar2 == ‘numeric’) { # Boxplot pour variable quantitative[cite: 5] p <- p + geom_boxplot(aes(x = v1, y = v2), fill = “skyblue”, color = “black”) } else if (typevar2 == ‘factor’) { # Barres empilées pour deux variables qualitatives[cite: 5] p <- p + geom_bar(aes(x = v1, fill = v2), position = “stack”) + labs(fill = labely) }

# Personnalisation des axes et du titre[cite: 5] p <- p + labs(title = titre, x = labelx, y = labely) + theme_minimal()

return(p) }

— ESSAI DE LA FONCTION —

On crée des données de test pour vérifier l’affichage[cite: 5]

test_v1 <- as.factor(c(“A”, “A”, “B”, “B”, “B”)) test_v2 <- c(10, 12, 15, 14, 18)

Appel qui génère le graphique dans le document[cite: 4]

f22309268(labelx=“Groupe”, titre=“Test Boxplot”, labely=“Valeur”, typevar2=‘numeric’, var1=test_v1, var2=test_v2)

Question 2

Question 3

Réponse :

Question 4

Réponse :

Question 5

Question 6

Question 7

Question 8

Réponse :

Question 9

Question 10

Réponse :