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
28 lines (22 loc) · 882 Bytes
/
Copy pathplot1.R
File metadata and controls
28 lines (22 loc) · 882 Bytes
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
LoadAndCleanData <- function() {
#Load data into memory
dat <- read.table("household_power_consumption.txt",
sep=";", header=T, na.strings=c("?"))
#Append datetime field based on Date and Time fields
dat$datetime <- strptime(paste(dat$Date, dat$Time),
format="%d/%m/%Y%H:%M:%S")
#Reduce dataset to dates of interest
dat <- subset(dat, as.Date(datetime) >= as.Date("2007-02-01"))
dat <- subset(dat, as.Date(datetime) <= as.Date("2007-02-02"))
dat
}
producePlot1 <- function(dat) {
titleText <- "Global Active Power"
xAxisText <- "Global Active Power (kilowatts)"
with(dat, hist(Global_active_power, col="red",
main=titleText, xlab=xAxisText))
}
#Run script.
#First produce clean data, then produce plot.
dat <- LoadAndCleanData()
producePlot1(dat)