forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.R
34 lines (30 loc) · 1.02 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
source("load_data.R")
plot4 <- function(data=NULL) {
if(is.null(data))
data <- loaddata()
png("plot4.png", width=504, height=504)
par(mfrow=c(2,2))
# plot diagram1
plot(data$Time, data$Global_active_power,
type="l",
xlab="",
ylab="Global Active Power")
# plot diagram2
plot(data$Time, data$Voltage, type="l",
xlab="datetime", ylab="Voltage")
# plot diagram3
plot(data$Time, data$Sub_metering_1, type="l", col="black",
xlab="", ylab="Energy sub metering")
lines(data$Time, data$Sub_metering_2, col="red")
lines(data$Time, data$Sub_metering_3, col="blue")
legend("topright",
col=c("black", "red", "blue"),
c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
lty=1, bty="n",
box.lwd=0)
# plot diagram4
plot(data$Time, data$Global_reactive_power, type="l",
xlab="datetime", ylab="Global_reactive_power")
lines(data$Time, data$Global_reactive_power)
dev.off()
}