forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.R
40 lines (32 loc) · 1.08 KB
/
plot4.R
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
source("load_data.R")
quad_plot <- function() {
par(mfrow=c(2, 2))
# 1st quadrant, global active power
with(power2, plot(DateTime, Global_active_power, type="l",
ylab="Global Active Power (kilowatts)",
xlab=""))
# 2nd quadrant, voltage
with(power2, plot(DateTime, Voltage, type="l"))
# 3rd quadrant, sub meterings
plot(power2$DateTime, power2$Sub_metering_1, type="l", col="Black",
ylab="Global Active Power (kilowatts)",
xlab="", ylim=c(0, 30))
lines(power2$DateTime, power2$Sub_metering_2,col="Red")
lines(power2$DateTime, power2$Sub_metering_3,col="Blue")
legend("topright",
legend=c("Sub_metering_1",
"Sub_metering_2",
"Sub_metering_3"),
lty=1,
bty="n",
col=c("Black",
"Red",
"Blue"))
# 4th quadrant, global reactive power
with(power2, plot(DateTime, Global_reactive_power, type="l"))
}
quartz()
par(mar=c(5.0, 4.0, 2.0, 1.5))
quad_plot()
dev.copy(png, file="plot4.png")
dev.off()