Setting up the defaults:
knitr::opts_chunk$set(echo = TRUE, results = "asis")
This assignment uses data from the UC Irvine Machine Learning Repository, a popular repository for machine learning datasets. In particular, we will be using the “Individual household electric power consumption Data Set” which I have made available on the course web site:
The following descriptions of the 9 variables in the dataset are taken from the UCI web site:
Keep in mind this course is about exploratory graphs, understanding the data, and developing strategies. Here’s a good quote from a swirl lesson about exploratory graphs: “They help us find patterns in data and understand its properties. They suggest modeling strategies and help to debug analyses. We DON’T use exploratory graphs to communicate results.”
The rubrics should always be interpreted in that context.
As you do your evaluation, please keep an open mind and focus on the positive. The goal is not to deduct points over small deviations from the requirements or for legitimate differences in implementation styles, etc. Look for ways to give points when it’s clear that the submitter has given a good faith effort to do the project, and when it’s likely that they’ve succeeded. Most importantly, it’s okay if a person did something differently from the way that you did it. The point is not to see if someone managed to match your way of doing things, but to see if someone objectively accomplished the task at hand. To that end, keep the following things in mind:
DO
DON’T:
Deduct just because you disagree with someone's statistical methods.
Our overall goal here is simply to examine how household energy usage varies over a 2-day period in February, 2007. Your task is to reconstruct the following plots below, all of which were constructed using the base plotting system. First you will need to fork and clone the following GitHub repository: https://github.com/rdpeng/ExData_Plotting1
For each plot you should
Load and clean the table:
t <- read.table("household_power_consumption.txt", header=TRUE, sep=";", na.strings = "?", colClasses = c('character','character','numeric','numeric','numeric','numeric','numeric','numeric','numeric'))
## Format date to Type Date
t$Date <- as.Date(t$Date, "%d/%m/%Y")
## Filter data set from Feb. 1, 2007 to Feb. 2, 2007
t <- subset(t,Date >= as.Date("2007-2-1") & Date <= as.Date("2007-2-2"))
## Remove incomplete observation
t <- t[complete.cases(t),]
## Combine Date and Time column
dateTime <- paste(t$Date, t$Time)
## Name the vector
dateTime <- setNames(dateTime, "DateTime")
## Remove Date and Time column
t <- t[ ,!(names(t) %in% c("Date","Time"))]
## Add DateTime column
t <- cbind(dateTime, t)
## Format dateTime Column
t$dateTime <- as.POSIXct(dateTime)
## Create the histogram
hist(t$Global_active_power, main="Global Active Power", xlab = "Global Active Power (kilowatts)", col="red")
## Save file and close device
#dev.copy(png,"plot1.png", width=480, height=480)
#dev.off()
## Create Plot 2
plot(t$Global_active_power~t$dateTime, type="l", ylab="Global Active Power (kilowatts)", xlab="")
#dev.copy(png,"plot2.png", width=480, height=480)
#dev.off()
## Create Plot 3
with(t, {
plot(Sub_metering_1~dateTime, type="l",
ylab="Global Active Power (kilowatts)", xlab="")
lines(Sub_metering_2~dateTime,col='Red')
lines(Sub_metering_3~dateTime,col='Blue')
})
legend("topright", col=c("black", "red", "blue"), lwd=c(1,1,1),
c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
## Saving to file
#dev.copy(png, file="plot3.png", height=480, width=480)
#dev.off()
## Create Plot 4
par(mfrow=c(2,2), mar=c(4,4,2,1), oma=c(0,0,2,0))
with(t, {
plot(Global_active_power~dateTime, type="l",
ylab="Global Active Power (kilowatts)", xlab="")
plot(Voltage~dateTime, type="l",
ylab="Voltage (volt)", xlab="")
plot(Sub_metering_1~dateTime, type="l",
ylab="Global Active Power (kilowatts)", xlab="")
lines(Sub_metering_2~dateTime,col='Red')
lines(Sub_metering_3~dateTime,col='Blue')
legend("topright", col=c("black", "red", "blue"), lty=1, lwd=2, bty="n",
legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
plot(Global_reactive_power~dateTime, type="l",
ylab="Global Rective Power (kilowatts)",xlab="")
})
## Saving to file
#dev.copy(png, file="plot4.png", height=480, width=480)
#dev.off()