forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot2.R
21 lines (18 loc) · 805 Bytes
/
plot2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
plot2 <- function () {
# load the data for 1-2 Feb 2007
pc1 <- loadPCdays()
# create the plot on a transparant background (is in the example provided)
par (bg='transparent', cex=0.75, omi=c(0, 0.05, 0, 0))
plot (pc1$DateTime, pc1$Global_active_power, type='l', ylab='Global Active Power (kilowatts)', xlab='')
# copy to the png file with the same size as the example provided
dev.copy(png, file = "plot2.png")
dev.off()
}
loadPCdays <- function () {
pc0 <<- read.csv('household_power_consumption.txt', sep=';', na.strings='?')
# select the rows for Feb 1-2, 2007
pc1 <- pc0[(pc0$Date=='1/2/2007')|(pc0$Date=='2/2/2007'),]
#add DateTime column
pc1$DateTime = strptime(paste (pc1$Date,pc1$Time, sep=' '), "%d/%m/%Y %H:%M:%S", tz='')
pc1
}