forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
15 lines (15 loc) · 919 Bytes
/
plot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#read data
mytable<-read.table(unz("exdata-data-household_power_consumption.zip","household_power_consumption.txt"), sep=";", header=T,na.strings = "?")
#change date format
mytable$datetime<-strptime(paste(mytable$Date,mytable$Time), "%d/%m/%Y %H:%M:%S")
mytable$Date<-as.Date(mytable$Date, "%d/%m/%Y")
#subset data
mytable<-subset(mytable,Date==as.Date("2007-02-01") | Date==as.Date("2007-02-02"))
#plot
png(filename="plot3.png")
with(mytable,plot(datetime,Sub_metering_1,type="n",ylab="Energy sub metering",xlab=""))
legend("topright", legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),lty=1,col=c("black","red","blue"))
with(mytable,lines(datetime,Sub_metering_1, ylab="Energy sub metering",xlab="",col="black"))
with(mytable,lines(datetime,Sub_metering_2, ylab="Energy sub metering",xlab="",col="red"))
with(mytable,lines(datetime,Sub_metering_3, ylab="Energy sub metering",xlab="",col="blue"))
dev.off()