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 (14 loc) · 968 Bytes
/
plot4.r
File metadata and controls
15 lines (14 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cat("Reading file, please wait...\n")
hpc <- read.table("household_power_consumption.txt", stringsAsFactors = FALSE, header=TRUE, sep=';')
hpc2 <- subset(hpc, Date=="1/2/2007" | Date=="2/2/2007")
dt <- strptime(paste(hpc2$Date, hpc2$Time), "%d/%m/%Y %H:%M:%S")
png(file="plot4.png")
par(mfcol = c(2, 2))
plot(dt, as.numeric(hpc2$Global_active_power), type="l", xlab="", ylab="Global Active Power")
with(hpc2, plot(dt, as.numeric(Sub_metering_1), type="l", xlab="", ylab="Energy sub metering"))
with(hpc2, points(dt, as.numeric(Sub_metering_2), type="l", col="Red"))
with(hpc2, points(dt, as.numeric(Sub_metering_3), type="l", col="Blue"))
legend("topright", col = c("black", "red", "blue"), legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty=1, bty="n")
plot(dt, as.numeric(hpc2$Voltage), type="l", xlab="datetime", ylab="Voltage")
plot(dt, as.numeric(hpc2$Global_reactive_power), type="l", xlab="datetime", ylab="Global_reactive_power")
dev.off()