forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
19 lines (12 loc) · 812 Bytes
/
plot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
data <- read.table("household_power_consumption.txt", header = TRUE, sep = ";", colClasses = c("character", "character", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric"),
na.strings = "?");
data <- data[data$Date %in% c("1/2/2007", "2/2/2007"),];
Sys.setlocale("LC_TIME", "C");
time <- strptime(paste(data$Date,data$Time,sep=" "),"%d/%m/%Y %H:%M:%S");
png(filename = "plot3.png", width = 504, height = 504, units = "px");
plot(time,data$Sub_metering_1, type="l", xlab = "", ylab = "Energy sub metering", col = "black");
lines(time,data$Sub_metering_2, col = "red");
lines(time,data$Sub_metering_3, col = "blue");
legend("topright", lty = 1, col = c("black", "red", "blue"),
legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"));
dev.off();