forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3.R
More file actions
17 lines (16 loc) · 763 Bytes
/
Copy pathplot3.R
File metadata and controls
17 lines (16 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
library(data.table)
library(lubridate)
library(dplyr)
temp <- read.table("household_power_consumption.txt", header=TRUE, sep= ";", na.strings = c("?",""))
temp$Date<-dmy(temp$Date)
df<- temp[year(temp$Date)== 2007 & month(temp$Date)==2 & mday(temp$Date) <3,]
rm(temp)
df$datetime <- paste(df$Date,df$Time)
df$Time <- strptime(df$datetime, format = "%Y-%m-%d %H:%M:%S")
df<-tbl_df(df[,1:9])
png(filename="plot3.png",width=480,height=480,units="px")
with(df,plot(Time,Sub_metering_1,type="l",ylab="Energy sub metering",xlab=""))
lines(df$Time,df$Sub_metering_2,col="red",type="l")
lines(df$Time,df$Sub_metering_3,col="blue",type="l")
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()