forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
18 lines (14 loc) · 900 Bytes
/
plot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
initial <- read.table(sep=";", file="household_power_consumption.txt", header=TRUE, nrows=100, comment.char = "", na.strings="?")
classes <- sapply(initial, class)
data <- read.table(sep=";", file="household_power_consumption.txt", header=TRUE, nrows=2075260, colClasses=classes, comment.char = "", na.strings="?")
data$Date <- as.Date(data$Date, format="%d/%m/%Y")
data_subset <- data[data$Date == "2007-02-01" | data$Date == "2007-02-02", ]
dt <- strptime(paste(data_subset$Date, data_subset$Time), format="%Y-%m-%d %H:%M:%S")
png(file = "plot3.png", width=480, height=480)
with(data_subset,
plot(dt, Sub_metering_1, type="l", ylab = "Energy sub metering", xlab="", col="black")
lines(dt, Sub_metering_2, col="red")
lines(dt, 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()