R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(shiny)
## Warning: package 'shiny' was built under R version 4.2.2
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.2.2
data=read.csv("C:/Users/Stacy/Downloads/ENB2012_data.csv")
View(data)
data= setNames(data, c(" RelativeCompactness","SurfaceArea","WallArea","RoofArea","OverallHeight"
                       ,"Orientation","GlazingArea","GlazingAreaDistribution","HeatingLoad","CoolingLoad" ))
View(data)
# Define UI
ui <- fluidPage(
  titlePanel("Energy Efficiency Dashboard 20BDS0246"),
  sidebarLayout(
    sidebarPanel(
      selectInput("variable", "Select a variable to display:",
                  choices = c( "SurfaceArea","WallArea","RoofArea","OverallHeight","RelativeCompactness",
                               "Orientation","GlazingArea","GlazingAreaDistribution","HeatingLoad","CoolingLoad")),
    ),
    mainPanel(
      plotOutput("scatterplot1"),
      plotOutput("scatterplot2"),
      plotOutput("histogram1"),
      plotOutput("histogram2")
    )
  )
)

# Define server
server <- function(input, output) {
  
  # Create scatter plot 1
  output$scatterplot1 <- renderPlot({
    ggplot(data, aes(x = data[[input$variable]], y = data$HeatingLoad)) +
      geom_point(aes(color = data$GlazingAreaDistribution)) +
      labs(x = input$variable, y = "Heating Load",
           title = paste("Heating Load vs.", input$variable)) +
      scale_color_gradient(low = "blue", high = "red")
  })
  
  # Create scatter plot 2
  output$scatterplot2 <- renderPlot({
    ggplot(data, aes(x = data[[input$variable]], y = data$CoolingLoad)) +
      geom_point(aes(color = data$SurfaceArea)) +
      labs(x = input$variable, y = "Cooling Load",
           title = paste("Cooling Load vs.", input$variable)) +
      scale_color_gradient(low = "blue", high = "red")
  })
  
  # Create histogram 1
  output$histogram1 <- renderPlot({
    ggplot(data, aes(x = data[[input$variable]])) +
      geom_histogram(fill = "blue", color = "black", bins = 30) +
      labs(x = input$variable, y = "Glazing Area",
           title = paste("Distribution of", input$variable, "in the Dataset"))
  })
  
  # Create histogram 2
  output$histogram2 <- renderPlot({
    ggplot(data, aes(x = data$HeatingLoad)) +
      geom_histogram(fill = "green", color = "black", bins = 30) +
      labs(x = "Heating Load", y = "Orientation",
           title = "Distribution of Heating Load in the Dataset")
  })
  
}

# Run the application
shinyApp(ui = ui, server = server)
Shiny applications not supported in static R Markdown documents

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.