forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.R
13 lines (13 loc) · 971 Bytes
/
plot4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
df <- read.csv("household_power_consumption.txt", sep=";", na.strings="?", colClasses=c(rep("character", 2),rep("numeric",7)))
plotDf <- subset(df, Date == "1/2/2007" | Date == "2/2/2007")
plotDf$Timestamp <- with(plotDf, strptime(paste(Date, Time), "%d/%m/%Y %H:%M:%S"))
png("plot4.png", width=480, height=480)
par(mfcol=c(2, 2))
with(plotDf, plot(Timestamp, Global_active_power, ylab="Global Active Power (kilowatts)", xlab="", type="l"))
with(plotDf, plot(Timestamp, Sub_metering_1, type="l", ylab="Energy sub metering", xlab=""))
with(plotDf, lines(Timestamp, Sub_metering_2, col="red", xlab="", ylab=""))
with(plotDf, lines(Timestamp, Sub_metering_3, col="blue", xlab="", ylab=""))
legend('topright', c("Sub_metering_1","Sub_metering_2", "Sub_metering_3"), col=c("black","red", "blue"), lty=c(1,1,1), bty="n")
with(plotDf, plot(Timestamp, Voltage, type="l", xlab="datetime"))
with(plotDf, plot(Timestamp, Global_reactive_power, type="l", xlab="datetime"))
dev.off()