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
28 lines (18 loc) · 1.13 KB
/
Copy pathplot4.R
File metadata and controls
28 lines (18 loc) · 1.13 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
# load, transform data
household_power_consumption <- read.csv("household_power_consumption.txt", sep=";", na.strings="?")
household_power_consumption$dtm = paste(household_power_consumption$Date, household_power_consumption$Time, sep = " ")
d1 <- transform(household_power_consumption, dtm = strptime(dtm, format = "%d/%m/%Y %H:%M:%S"))
dt <- subset(d1, dtm >= as.POSIXlt("2007-02-01 00:00:00") & dtm <= as.POSIXlt("2007-02-02 23:59:00"))
# produce plot
png(file = "plot4.png")
par(mfrow = c(2,2), mar = c(4,4,2,1), oma = c(0, 0, 2, 0))
with(dt, plot(dtm, Global_active_power, ylab = "Global Active Power", xlab = "", type = "l"))
with(dt, plot(dtm, Voltage, ylab = "Voltage", xlab = "datetime", type = "l"))
{
with(dt, plot(dtm, Sub_metering_1, ylab = "Energy sub metering", xlab = "", type = "l"))
lines(dt$dtm, dt$Sub_metering_2, type = "l", col = "red")
lines(dt$dtm, dt$Sub_metering_3, type = "l", col = "blue")
legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty=c(1,1, 1), col=c("black", "red","blue"), cex = 0.8, bty = "n")
}
with(dt, plot(dtm, Global_reactive_power, xlab = "datetime", type = "l"))
dev.off()