forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot3.R
13 lines (13 loc) · 776 Bytes
/
plot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
power0 <- read.table("household_power_consumption.txt", header = TRUE,sep=";",na.strings = "?")
power0$DT <- paste(power0$Date,power0$Time,sep=" ")
power0$DateTime <- strptime(power0$DT,"%d/%m/%Y %H:%M:%S")
date1 <- as.POSIXlt("2007-02-01 00:00:00")
date2 <- as.POSIXlt("2007-02-02 24:00:00")
power <- power0[(power0$DateTime>=date1)&(power0$DateTime<=date2),]
png(filename = "plot3.png",height = 480,width=480)
with(power,plot(DateTime,Sub_metering_1, ylab = "Energy sub metering",type="n"))
with(power,lines(DateTime,Sub_metering_1))
with(power,lines(DateTime,Sub_metering_2,col="red"))
with(power,lines(DateTime,Sub_metering_3,col="blue"))
legend("topright",lwd = c(1,1,1), col=c("black","red","blue"),legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"))
dev.off()