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
15 lines (15 loc) · 995 Bytes
/
plot4.R
File metadata and controls
15 lines (15 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
unzip("household_power_consumption.zip")
data <- read.table("household_power_consumption.txt", sep = ";", dec = ".", header = TRUE, stringsAsFactors=FALSE)
data <- rbind(data[which(data$Date == "1/2/2007"),], data[which(data$Date == "2/2/2007"),])
datetime <- strptime(paste(data$Date , data$Time), "%d/%m/%Y %H:%M:%S")
png(filename = "plot4.png", width = 480, height = 480)
par(mfrow = c(2,2), mar = c(4,2,2,2))
plot(datetime, data[,3], type = "l", ylab = "Global Active Power", xlab = " ")
plot(datetime, data[,5], type = "l", ylab = "Voltage", xlab = "datetime")
plot(datetime, data[,7], type = "l", ylab = "Energy sub metering", xlab = " ")
lines(datetime, data[,8], col = "red")
lines(datetime, data[,9], 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"),bty="n")
plot(datetime, data[,4], type = "l", ylab = "Global_reactive_power", xlab = "datetime")
axis(2, at=c(0.1,0.2,0.3,0.4,0.5))
dev.off()