forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot2.R
30 lines (21 loc) · 956 Bytes
/
plot2.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
25
26
27
28
29
## Plot 2
# setwd("~/Work/Ds/ExploratoryDataAnalysis") # dir where R can find "household_power_consumption.txt"
## Load data
Data = read.csv2(file="household_power_consumption.txt", dec=".", na.strings="?", colClasses=c(rep("character", 2), rep("numeric", 7)))
DateTime = paste(Data$Date, Data$Time)
Data$DateTime = strptime(DateTime, "%d/%m/%Y %H:%M:%S") # convert to POSIXlt
Data$Date = as.Date(Data$Date, "%d/%m/%Y")
SelDate = Data$Date >= "2007-02-01" & Data$Date <= "2007-02-02"
Data2 = Data[SelDate,]
rm(Data)
## Plot
IdxThu = min(which(Data2$Date == "2007-02-01"))
IdxFri = min(which(Data2$Date == "2007-02-02"))
IdxSat = max(which(Data2$Date == "2007-02-02")) + 1
IdxLabel = c(IdxThu, IdxFri, IdxSat)
Label = c("Thu", "Fri", "Sat")
png("plot2.png", height=480, width=480)
with(Data2, {
plot(Global_active_power, xlab="", ylab="Global Active Power (kilowatts)", type="l", xaxt="n");
axis(1, at=IdxLabel, labels=Label)})
dev.off()