-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3.R
More file actions
21 lines (17 loc) · 894 Bytes
/
plot3.R
File metadata and controls
21 lines (17 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Read file
power = read.table("household_power_consumption.txt", header = TRUE,
sep = ";", na.strings = "?");
power$Date = as.Date(power$Date, format = "%d/%m/%Y");
powerFeb = subset(power, Date == "2007-02-01" | Date == "2007-02-02");
datetime = paste(powerFeb$Date, powerFeb$Time);
powerFeb$datetime = strptime(datetime, format = "%Y-%m-%d %H:%M:%S");
## Plot 3
png(filename = "plot3.png",
width = 480, height = 480, units = "px", bg = "white")
with(powerFeb, plot(datetime, Sub_metering_1, col = "black", type = "l",
xlab = NA, ylab = "Energy sub metering"))
with(powerFeb, lines(datetime, Sub_metering_2, col = "red", type = "l"))
with(powerFeb, lines(datetime, Sub_metering_3, col = "blue", type = "l"))
legend("topright", lty = c(1,1,1), col = c("black", "red", "blue"),
legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
dev.off();