forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3.R
More file actions
23 lines (23 loc) · 996 Bytes
/
plot3.R
File metadata and controls
23 lines (23 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
download.file("https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip", "prj1.zip")
unzip("prj1.zip")
unlink("prj1.zip")
raw <- read.table("household_power_consumption.txt",
header = TRUE, sep = ";", dec = ".", stringsAsFactors = F)
data <- raw[which(raw[[1]] == "1/2/2007" | raw[[1]] == "2/2/2007"), ]
data[[1]] <- paste(data[[1]], data[[2]])
data <- data[,-2]
for(i in 1:7){
if(i == 1) {
data[[i]] <- strptime(data[[i]], format = "%d/%m/%Y %H:%M:%OS")
} else{
data[[i]] <- as.numeric(data[[i]])
}
}
# plot3
png(filename = "plot3.png", width = 480, height = 480, units = "px")
with(data, plot(Date, Sub_metering_1, type = "l", col = "black",
ylab = "Energy sub metering", xlab = NA))
with(data, lines(Date, Sub_metering_2, type = "l", col = "red"))
with(data, lines(Date, Sub_metering_3, type = "l", col = "blue"))
legend("topright", legend = names(data)[6:8], lty = 1, col = c("black", "red", "blue"))
dev.off()