Assignment 3 Presentation

Anonymous
25 September 2017

Introduction

The purpose of this presentation is to give information on the R Shiny application created for the Coursera Data Products final assignment.

The R Shiny App can be found here.

The GIthub code can be found here.

The Application

The Application is called “K-means CLustering of Select Datasets”. It allows the user to select from a list of standard R datasets and then plot them on the right with clustering visualised. The user has the ability to select the X & Y variable for each dataset as well as the cluster count for the visualisation.

Note: The cluster count has a minimum of 1 and maximum of 3. Datasets Available are:

  • USArrests
  • USJudgeRatings
  • ChickWeight
  • cars
  • iris
  • mtcars

Code Breakdown (Part 1)

Let us take a look at some of the code.

First we can see that we have drop downs for our dataset, x variable & y variable. The code for the Y variable is shown below.

# Drop-down selection box for yvar
  output$choose_yvar <- reactiveUI(function() {
    dat <- get(input$dataset)
    colnames <- names(dat)
    selectInput("yvar", "Y Variable", as.list(colnames),selected=colnames[2])
  })

Code Breakdown (Part 2)

Finally we create our plot!

# Create the plot
  output$plot1 <- renderPlot({
# Set colours for 7 clusters
    palette(c("red", "blue", "green", "orange",
              "purple", "yellow", "black"))
# Margins    
    par(mar = c(5.1, 4.1, 0, 1))
    plot(selectedData(),
         col = clusters()$cluster,
         pch = 20, cex = 4)
    points(clusters()$centers, pch = 3, cex = 5, lwd = 3)
  })