forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.R
18 lines (18 loc) · 1.08 KB
/
plot4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
POW <- read.csv("household_power_consumption.txt", sep = ";", colClasses=rep("character",9))
POW[POW == "?"] <- NA
POW$Time <- strptime((paste(POW$Date,POW$Time,sep = "-")),format = "%d/%m/%Y-%H:%M:%S")
POW$Time <- as.POSIXct(POW$Time)
POW$Date <- as.Date(POW$Date, format="%d/%m/%Y")
POW$Global_active_power <- as.numeric(POW$Global_active_power)
POW <- subset(POW, POW$Date >= as.Date("2007-02-01",format="%Y-%m-%d") & POW$Date <= as.Date("2007-02-02",format="%Y-%m-%d"))
png(file="plot4.png",width=480,height=480)
par(mfcol=c(2,2))
plot(POW$Global_active_power~POW$Time,type="l",ylab="Global Active Power (kilowatts)",xlab="")
plot(POW$Sub_metering_1~POW$Time, type="n",ylab="Energy sub metering",xlab="")
lines(POW$Sub_metering_1~POW$Time)
lines(POW$Sub_metering_2~POW$Time, col="red")
lines(POW$Sub_metering_3~POW$Time, col="blue")
legend("topright", lty = 1, legend=colnames(POW)[7:9], col=c("black","red","blue"),bty="n")
plot(POW$Voltage~POW$Time,type="l",ylab="Voltage",xlab="datetime")
plot(POW$Global_reactive_power~POW$Time,type="l",ylab="Global_reactive_power",xlab="datetime")
dev.off()