Introduction

This is an exploratory analysis of weather data gathered for the Capacity Management Modeling project.

It assumes that weather data has already been downloaded from the Internet and stored in a SQL Server table

Prepare Workspace

rm(list=ls())

## Working directory and path variables
setwd("\\\\ccor_ds\\common\\dbase\\PredModCapMgmt_P1356\\preparation\\analysis\\R")
datapath <- "\\\\ccor_ds\\common\\dbase\\PredModCapMgmt_P1356\\preparation\\analysis\\R\\Data"
codepath <- "\\\\ccor_ds\\common\\dbase\\PredModCapMgmt_P1356\\preparation\\analysis\\R\\Code"

## Load libraries
require(ggplot2) ## for vizualisations

## Warning: package 'weatherData' was built under R version 3.3.1
require("RODBC") ## for ODBC data commands

Retrieve Weather Data from SQL Server

## Create a connection channel to the SQL Server database. Uses integrated security.
ch <- odbcConnect("CapacityMgt")

## Create SQL query to select weather table data
sql <- "SELECT [rownames],[Time],[TimeEDT],[TemperatureF],[Dew_PointF],[Humidity],[Sea_Level_PressureIn],[VisibilityMPH],[Wind_Direction],[Wind_SpeedMPH],[Gust_SpeedMPH],[PrecipitationIn],[Events],[Conditions],[WindDirDegrees],[DateUTC],[TimeEST] FROM [dbo].[tblWeather]"


## Execute query
weatherdf <- as.data.frame(sqlQuery(ch, sql))

dim(weatherdf)
## [1] 32696    17
close(ch)

Find Maximum Temperature Per Day

library(lubridate)

## str(weatherdf)

weatherdf$Date <- lubridate::date(weatherdf$Time)

weatherdf$Year <- lubridate::year(weatherdf$Time)

maxtemps <- aggregate(weatherdf$TemperatureF, by = list(weatherdf$Date), max)

colnames(maxtemps) <- c("Date", "MaxTemp")

head(maxtemps)
##         Date MaxTemp
## 1 2013-08-01    77.0
## 2 2013-08-02    84.0
## 3 2013-08-03    78.1
## 4 2013-08-04    80.1
## 5 2013-08-05    78.1
## 6 2013-08-06    73.0
ggplot(maxtemps, aes(x = Date, y = MaxTemp)) +
  geom_point() +
  geom_smooth(method = "lm") +
  ggtitle("Temperature Trend 2013 - 2016, New Castle, Delaware") +
  ylab("Daily Max Temp Farenheit")