forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot1.R
More file actions
81 lines (65 loc) · 3.91 KB
/
Copy pathPlot1.R
File metadata and controls
81 lines (65 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
## Program : Coursera Data Science - Exploratory Data Analysis Peer Assessment 1
## Written By : Gabriel Mohanna
## Date Created: May 6, 2014
##
## Narrative : Our overall goal is to examine how household energy usage varies over a 2-day period in February,
## 2007. Your task is to reconstruct some plots, all of which were constructed using the base plotting
## system.
##
## Background : 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". The data contains measurements of electric power consumption in one household
## with a one-minute sampling rate over a period of almost 4 years. Different electrical quantities and
## some sub-metering values are available.
##
## TBD :
##
## \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
## <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Code is Poetry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
## //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
##
## **********************************************************************************************************************
## Steps
## -----
## (0) Load Libraries & Define Data Path
## (1) Read Data
## (2) Plot 1: Histogram of Global Active Power
##
## **********************************************************************************************************************
## Notes
## ---------------------
##
## **********************************************************************************************************************
# ***********************************************************************************************************************
# (0) Load Libraries & Define Data Path
# ***********************************************************************************************************************
# Load Libraries
library(lubridate)
# Define Data Path
data_path <- "D:/Users/gmohanna/SkyDrive/Documents/HW/Coursera/Exploratory Data Analysis/Projects/Project 1"
setwd(data_path)
# End Load Libraries & Define Data Path
# ***********************************************************************************************************************
# (1) Read Data
# ***********************************************************************************************************************
# Download, read & subset data
download.file(url = "http://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip",
destfile = "./Data/Household Power Consumption.zip")
data <- read.table(unz("Data/Household Power Consumption.zip", "household_power_consumption.txt"), header=T, quote="\"", sep=";", na.strings="?")
# Convert date from factor to date
data$Date <- as.Date(data$Date, format="%d/%m/%Y")
# Subset data
data <- data[data$Date >= as.Date("2007-02-01") & data$Date <= as.Date("2007-02-02"), ]
# Create Date/Time stamp
data$DateTime <- strptime(paste(data$Date, data$Time), format="%Y-%m-%d %H:%M:%S", tz="EST")
# End Read Data
# ***********************************************************************************************************************
# (2) Plot 1: Histogram of Global Active Power
# ***********************************************************************************************************************
# Open PNG device; create 'Plot1.png' in working directory
png(filename = "Plot1.png", width=480, height=480, bg="transparent")
# Create plot and send to a file (no plot appears on screen)
hist(x=data$Global_active_power, main="Global Active Power", col="red",xlab="Global Active Power (killowatts)")
# Close the PNG file device
dev.off()
# End Plot 1: Histogram of Global Active Power