HAX815X - R programming
Résumé de section
-
-
Practical 1 Interactive visualisation with
mtcarsObjective Create a Shiny application to visualise the relationships between different variables in the
mtcarsdataset.Instructions
- Use
selectInput()to allow the user to select two numerical variables from themtcarsdataset. - Display an interactive scatter graph (
ggplot2). - Add a
sliderInput()to adjust the size of the points.
library(ggplot2)
ui <- fluidPage(
titlePanel("Visualisation interactive des données mtcars"),
sidebarPanel(
selectInput("xvar", "Choisissez la variable X :", choices = names(mtcars)),
selectInput("yvar", "Choisissez la variable Y :", choices = names(mtcars)),
sliderInput("pointSize", "Taille des points :", min = 1, max = 10, value = 3)
),
mainPanel(
plotOutput("scatterPlot"), width = 20)
)
server <- function(input, output) {
output$scatterPlot <- renderPlot({
ggplot(mtcars, aes_string(x = input$xvar, y = input$yvar)) +
geom_point(size = input$pointSize, color = "blue") +
theme_minimal() +
labs(title = "Graphique de dispersion", x = input$xvar, y = input$yvar)
})
}
shinyApp(ui, server)Practical 2 Analysing
irisdataObjective To enable the user to explore
irisdata using statistics and visualisations.Instructions
- Add a
selectInput()to choose a species (setosa,versicolor,virginica). - Filter the data according to the selected species.
- Display :
- A statistical summary (
summary()) of the numerical variables. - A boxplot of the distribution of sepal lengths by species (
ggplot2).
library(ggplot2)
ui <- fluidPage(
sidebarPanel(
selectInput("species", "Sélectionnez une espèce :", choices = unique(iris$Species))
),
mainPanel(
verbatimTextOutput("summaryStats"),
plotOutput("boxplotSepalLength")
)
)
server <- function(input, output) {
filteredData <- reactive({
iris[iris$Species==input$species,]
})
output$summaryStats <- renderPrint({
summary(filteredData()[, 1:4]) # Exclure la colonne Species
})
output$boxplotSepalLength <- renderPlot({
ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
geom_boxplot() +
theme_minimal() +
labs(title = "Longueur des sépales par espèce")
})
}
shinyApp(ui, server)Practical 3 Analysis of the passengers on the Titanic (
titanicfrom thedatasetspackage)Objective To study the distribution of passengers according to class and survival.
Instructions
- Load the dataset with
data(‘Titanic’)and convert it todata.frame. - Add
checkboxGroupInput()to allow the user to filter passengers by class and gender. - Display :
- A reactive array (
DT::datatable()). - A bar chart of the number of survivors and non-survivors (
ggplot2).
ui <- fluidPage(
titlePanel("Analyse des données Titanic"),
sidebarLayout(
sidebarPanel(
checkboxGroupInput("class", "Choisir la classe :", choices = unique(titanic_df$Class), selected = unique(titanic_df$Class)),
checkboxGroupInput("sex", "Choisir le sexe :", choices = unique(titanic_df$Sex), selected = unique(titanic_df$Sex))
),
mainPanel(
DTOutput("tableTitanic"),
plotOutput("barPlotSurvival")
)
)
)
server <- function(input, output) {
filteredData <- reactive({
titanic_df %>%
filter(Class %in% input$class, Sex %in% input$sex)
})
output$tableTitanic <- renderDT({
datatable(filteredData())
})
output$barPlotSurvival <- renderPlot({
ggplot(filteredData(), aes(x = Survived, y = Freq, fill = Survived)) +
geom_bar(stat = "identity") +
theme_minimal() +
labs(title = "Répartition des survivants et non-survivants", x = "Survie", y = "Nombre de passagers")
})
}
shinyApp(ui, server) - Use
-
Submission deadline
Friday 17 April 2026email GitHub repository
SSD
Groupe 1 : Mamy Rodrigue et Soumah OusmaneGroupe 2 : Bahraoui Ines et Bouaziz Chams-Eddine
Groupe 3 : Daoudi Marouane
Groupe 4 : Ben-Atmane Sofia et Camus Ines
Groupe 5 : Benaissa Hadjer et El-Idrissi Myriam
Groupe 6 : Karimou Firdaousse et Monmont Chloe
Groupe 7 : Benameur Lea
Groupe 8 : Jabri Mohammed
Groupe 9 : Dahoud Aly et Remila Dalia
Groupe 10 : Benameur Karam et El-Mahzoum Akram
Groupe 11 : Assoumani Ben-Enfane et Maloum Ayoub
Groupe 12 : Diagne Moussa et Agossou Dossou-Modeste
Groupe 13 : Djossou Houenafa-Esperance-G
Groupe 14 : Maggi Bastien et Regnat Neo
Groupe 15 : Yonkeu-Waya Kevin-Roseverlt
BIOINFO
Groupe 1 : Morlevat Theo et Pariente Marie-CharlotteGroupe 2 : Hoang Thao-Anh et Lateur Axelle