forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.R
50 lines (40 loc) · 1.04 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
41
42
43
44
45
46
47
48
49
50
source("loadData.R")
# function to be called from command line to run plot
plot4 <- function(){
#load data using function written in "loadData.R"
data <- loadData()
png("plot4.png", width=400, height=400)
par(mfrow=c(2,2))
#plot 1
plot(data$Time, data$Global_active_power,
ylab="Global Active Power",
xlab="",
type="l"
)
#plot 2
plot(data$Time, data$Voltage,
ylab="Voltage",
xlab="datetime",
type="l"
)
#plot 3
plot(data$Time, data$Sub_metering_1,
ylab="Energy sub metering",
xlab="",
type="l"
)
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"),
legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
lty=1,
box.lwd=0)
#plot 4
plot(data$Time, data$Global_reactive_power,
ylab="Global_reactive_power",
xlab="datetime",
type="l"
)
dev.off()
}