forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot4.R
More file actions
30 lines (23 loc) · 1.19 KB
/
plot4.R
File metadata and controls
30 lines (23 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
plot4<-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])
}
par(mfrow = c(2,2))
with(data, plot(DateTime, Global_active_power, type="l", xlab="", ylab="Global Active Power"))
with(data, plot(DateTime, Voltage, type="l", xlab="datetime", ylab="Voltage"))
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", bty="n", lty = "solid", col = c("black", "red", "blue"), legend = c("Sub_metering_1","Sub_metering_2", "Sub_metering_3"))
with(data, plot(DateTime, Global_reactive_power, type="l", xlab="datetime", ylab="Global Reactive Power"))
dev.copy(png, width=480, height=480, file = "plot4.png")
dev.off()
}