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
31 lines (22 loc) · 1.18 KB
/
plot4.R
File metadata and controls
31 lines (22 loc) · 1.18 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
30
31
data <- read.table("household_power_consumption.txt", sep = ";", header = TRUE, stringsAsFactors = FALSE)
data[,"Date"] <- as.Date(data[,"Date"],format = "%d/%m/%Y")
sdata <- subset(data,Date == "2007-02-01" | Date == "2007-02-02")
GlobActPow <- suppressWarnings(as.numeric(sdata[,"Global_active_power"]))
datet <- strptime(paste(sdata$Date,sdata$Time,sep = " "), "%Y-%m-%d %H:%M:%S" )
sub1 <- as.numeric(sdata[,"Sub_metering_1"])
sub2 <- as.numeric(sdata[,"Sub_metering_2"])
sub3 <- as.numeric(sdata[,"Sub_metering_3"])
GlobReaPow <- as.numeric(sdata[,"Global_reactive_power"])
Volt <- as.numeric(sdata[,"Voltage"])
png("plot4.png",width = 480, height = 480)
par(mfrow = c(2,2))
plot(datet,GlobActPow,type = "l",xlab = " ",ylab = "Global Active Power")
plot(datet,Volt,type = "l",xlab = "datetime",ylab = "Voltage")
plot(datet,sub1,col = "black",type = "l", xlab = " ", ylab = "Energy sub metering")
lines(datet, sub2, col = "red")
lines(datet, sub3, col = "blue")
legend("topright",
legend = c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),
lty = c(1,1,1), col = c("black","red","blue"))
plot(datet,GlobReaPow,type = "l",xlab = "datetime",ylab = "Global_reactive_power")
dev.off()