forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
14 lines (14 loc) · 904 Bytes
/
plot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
data <- read.table("household_power_consumption.txt", sep = ";", header = TRUE, na.string = "?")
data$Date <- as.Date(data$Date, format = "%d/%m/%Y")
data$Time <- format(strptime(data$Time, format = "%H:%M:%S"), format = "%H:%M:%S")
mod_data <- data[data$Date == "2007-02-01" | data$Date == "2007-02-02", ]
mod_data <- na.omit(mod_data)
mod_data$DT <- strptime(paste(mod_data$Date, mod_data$Time), format = "%Y-%m-%d %H:%M:%S")
png(file = "plot3.png")
par(bg = "transparent")
with(mod_data, plot(DT, Sub_metering_1, type = "n", ylab = "Energy sub metering",xlab = ""))
lines(mod_data$DT, mod_data$Sub_metering_1, type = "l" )
lines(mod_data$DT, mod_data$Sub_metering_2, type = "l", col = "red" )
lines(mod_data$DT, mod_data$Sub_metering_3, type = "l", col = "blue" )
legend("topright", legend = c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),lty=c(1,1,1), col = c("black","red","blue"))
dev.off()