forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot2.R
More file actions
29 lines (23 loc) · 887 Bytes
/
plot2.R
File metadata and controls
29 lines (23 loc) · 887 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
29
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
}
producePlot2 <- function(dat) {
yAxisText <- "Global Active Power (kilowatts)"
with(dat, {
plot(datetime, Global_active_power, xlab="", ylab=yAxisText, type="n")
lines(datetime, Global_active_power)
})
}
#Run script.
#First produce clean data, then produce plot.
dat <- LoadAndCleanData()
producePlot2(dat)