forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
24 lines (18 loc) · 826 Bytes
/
plot3.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
# plot3.R
df <- read.table("household_power_consumption.txt",
skip = 66637, nrow = 2880, sep = ";",
col.names = colnames(read.table(
"household_power_consumption.txt",
nrow = 1, header = TRUE, sep=";")))
png("plot3.png")
Sys.setlocale("LC_TIME", "C")
w <- strptime(paste(df$Date, df$Time), format = "%d/%m/%Y %H:%M:%S")
# plot the Sub_metering_1 across the week days
plot(w, df$Sub_metering_1, type = "l", xlab = "", ylab = "Energy sub metering")
# add Sub_metering_2 in red
lines(w, df$Sub_metering_2, type = "l", col = "red")
# add Sub_metering_3 in blue
lines(w, df$Sub_metering_3, type = "l", col = "blue")
# add a legend in the topright
legend("topright", lty = c(1, 1), col = c("black", "red", "blue"), legend = names(df[7:9]))
dev.off()