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
22 lines (19 loc) · 896 Bytes
/
plot3.R
File metadata and controls
22 lines (19 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
plot3<-function(){
data<-read.table("household_power_consumption.txt", header=TRUE, sep=";", nrows=69520, colClasses="character")
data<-data[66637:69516,]
DateTime<-paste(data[,"Date"], data[,"Time"], sep=" ")
DateTime<-strptime(DateTime, "%d/%m/%Y %X")
data<-cbind(DateTime, data)
data<-subset(data, select=-c(Date,Time))
index<-2:8
for(i in index){
data[,i]<-as.numeric(data[,i])
}
with(data, plot(DateTime, Sub_metering_1, type="n", xlab="", ylab="Energy sub metering"))
with(data, lines(DateTime, Sub_metering_1, type="l", col="black"))
with(data, lines(DateTime, Sub_metering_2, type="l", col="red"))
with(data, lines(DateTime, Sub_metering_3, type="l", col="blue"))
legend("topright", lty = "solid", col = c("black", "red", "blue"), legend = c("Sub_metering_1","Sub_metering_2", "Sub_metering_3"))
dev.copy(png, width=480, height=480, file = "plot3.png")
dev.off()
}