Aperçu des sections

  • Basic concepts

  • Functionnal programming

  • Developing an R package

  • ggplot2

  • R shiny : building interactive graphical applications

    • Practical 1 Interactive visualisation with mtcars

      Objective Create a Shiny application to visualise the relationships between different variables in the mtcars dataset.

      Instructions

      1. Use selectInput() to allow the user to select two numerical variables from the mtcars dataset.
      2. Display an interactive scatter graph (ggplot2).
      3. Add a sliderInput() to adjust the size of the points.
      library(shiny)
      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 iris data

      Objective To enable the user to explore iris data using statistics and visualisations.

      Instructions

      1. Add a selectInput() to choose a species (setosaversicolorvirginica).
      2. Filter the data according to the selected species.
      3. Display :
        • statistical summary (summary()) of the numerical variables.
        • boxplot of the distribution of sepal lengths by species (ggplot2).
      library(shiny)
      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 (titanic from the datasets package)

      Objective To study the distribution of passengers according to class and survival.

      Instructions

      1. Load the dataset with data(‘Titanic’) and convert it to data.frame.
      2. Add checkboxGroupInput() to allow the user to filter passengers by class and gender.
      3. Display :
        • reactive array (DT::datatable()).
        • bar chart of the number of survivors and non-survivors (ggplot2).
      titanic_df <- as.data.frame(Titanic)

      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)

  • Rewriting R code in C++

  • Data management

  • Project

  • Evaluation