forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot3.R
20 lines (17 loc) · 869 Bytes
/
plot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
skip <- 66637
end <- 69517
filename <- "household_power_consumption.txt"
mycolnames <- c("Date","Time","Global_active_power","Global_reactive_power","Voltage","Global_intensity","Sub_metering_1","Sub_metering_2","Sub_metering_3")
df <- read.table(filename, sep = ";", na.strings = "?", skip = skip, nrows = end-skip)
colnames(df) <- mycolnames
png(file = "plot3.png")
DateTime <- paste(df$Date, df$Time)
DateTime <- as.POSIXct(DateTime, format = "%d/%m/%Y %H:%M:%S")
df$DateTime <- DateTime
plot(df$DateTime, df$Sub_metering_1, type="l", col = "black",
xlab = "", ylab = "Energy sub metering")
points(df$DateTime, df$Sub_metering_2, type="l", col = "red")
points(df$DateTime, df$Sub_metering_3, type="l", col = "blue")
legend("topright", col = c("black","red","blue"), lty=c(1,1),
legend = c("Sub_metering_1","Sub_metering_2","Sub_metering_3"))
dev.off()