forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot1.R
24 lines (20 loc) · 901 Bytes
/
plot1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
plot1 <- function () {
# load the data for 1-2 Feb 2007
pc1 <- loadPCdays()
# png (filename ='plot1.png', bg ='transparent', width=504, height=504)
# 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))
hist(pc1$Global_active_power, col='red', main='Global Active Power',
xlab='Global Active Power (kilowatts)')
# copy to the png file with the same size as the example provided
dev.copy(png, file = "plot1.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
}