SAT scores and teacher salaries

show with app
  • app.R
library(shiny)
library(mosaic)
library(ggplot2)

ui <- shinyUI(fluidPage(
  # Application title
  titlePanel("SAT scores and teacher salaries"),

  sidebarLayout(
    sidebarPanel(
      selectInput("stratify", "Stratify by percent taking SAT?",
                  choices = c("Yes", "No"), selected="No")),
    # Show a plot of the generated distribution
    mainPanel(plotOutput("distPlot"))
  )
))


server <- shinyServer(function(input, output) {
  output$distPlot <- renderPlot({
 
    # create new variable
    SAT <- mutate(SAT, fracgrp = cut(frac, 
      breaks=c(0, 22, 49, 81), 
      labels=c("low fraction", "medium fraction", "high fraction")))

    # generate the desired plot
    p <- ggplot(SAT, aes(x = salary, y = sat)) + stat_smooth(method = lm) + geom_point()
    if (input$stratify == "Yes") {
      p <- p + aes(colour = fracgrp) 
    }
    return(p)
  })
})



# Run the app ----
shinyApp(ui = ui, server = server)