Nom : Terras
Prénom : Omar
Numéro étudiant :22309268
{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
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) }
test_v1 <- as.factor(c(“A”, “A”, “B”, “B”, “B”)) test_v2 <- c(10, 12, 15, 14, 18)
f22309268(labelx=“Groupe”, titre=“Test Boxplot”, labely=“Valeur”, typevar2=‘numeric’, var1=test_v1, var2=test_v2)
Réponse :
Réponse :
Réponse :
Réponse :