forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlot4.R
21 lines (17 loc) · 1.05 KB
/
Plot4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
indata<-read.table("household_power_consumption.txt",header=TRUE, sep=";", dec=".",na.strings="?")
shortdata<-indata[which(indata$Date=="1/2/2007" | indata$Date == "2/2/2007"),]
rm(indata)
dateTime <- strptime(paste(shortdata$Date,shortdata$Time,sep=" "),"%d/%m/%Y %H:%M:%S")
shortdata$dateTime <- dateTime
par(mfrow=c(2,2))
with(shortdata,{
plot(shortdata$dateTime,shortdata$Global_active_power,type="l", xlab="", ylab="Global Active Power")
plot(shortdata$dateTime,shortdata$Voltage,type="l", xlab="datetime", ylab="Voltage")
plot(shortdata$dateTime,shortdata$Sub_metering_1,type="l", xlab="", ylab="Energy sub metering")
lines(shortdata$dateTime, shortdata$Sub_metering_2,type="l",col="red")
lines(shortdata$dateTime, shortdata$Sub_metering_3,type="l",col="blue")
legend("topright", lty=1, bty="n", col = c("black", "red", "blue"), legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
plot(shortdata$dateTime,shortdata$Global_reactive_power,type="l", xlab="datetime", ylab="Global_reactive_power")
})
dev.copy(png, file="plot4.png")
dev.off()