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
49 lines (42 loc) · 1.35 KB
/
plot4.R
File metadata and controls
49 lines (42 loc) · 1.35 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# common code to load the dates in question
full <-
read.table(
"household_power_consumption.txt", header = TRUE, sep = ";",na.strings =
"?"
)
dates <- as.Date(full$Date, "%d/%m/%Y")
datetimes <-
strptime(paste(full$Date, full$Time), format = "%d/%m/%Y %H:%M:%S", tz =
"UTC")
full$datetime <- datetimes
ourdata <-
subset(full, ((datetimes$year == 107) &
(datetimes$mon == 1) &
((datetimes$mday == 1) | (datetimes$mday == 2)
)))
# end common code to load the dates in question
png(filename = "plot4.png")
# 2x2 matrix of plots
# default margins ok, don't need to set e.g. par(mfcol = c(2,2), mar = c(4, 4, 2, 1), oma = c(0, 0, 2, 0))
par(mfcol = c(2,2))
with(ourdata, {
#upper left
plot(
datetime, Global_active_power, type = "l", xlab = "", ylab = "Global Active Power"
)
#lower left
plot(
datetime, Sub_metering_1, type = "l", xlab = "", ylab = "Energy sub metering"
)
lines(datetime, Sub_metering_2, col = "red")
lines(datetime, Sub_metering_3, col = "blue")
legend(
"topright", legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), col =
c("black", "red", "green"), lty = c(1,1,1), bty = "n"
)
#upper right
plot(datetime, Voltage, type = "l")
#lower right
plot(datetime, Global_reactive_power, type = "l")
})
dev.off()