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
39 lines (30 loc) · 924 Bytes
/
plot4.R
File metadata and controls
39 lines (30 loc) · 924 Bytes
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
source("prepare_data.R")
loaddata()
# Plot part
png(file = "plot4.png", width = 480, height = 480)
par(mfrow=c(2,2))
# Plot 1
plot(dat$DateTime, dat$Global_active_power,
type = "l",
xlab = "", ylab = "Global Active Power")
# Plot 2
plot(dat$DateTime, dat$Voltage,
type = "l",
xlab = "datetime",
ylab = "voltage")
# Plot 3
plot(dat$DateTime, dat$Sub_metering_1,
type = "n",
xlab = "", ylab = "Energy sub metering")
lines(dat$DateTime, dat$Sub_metering_1, col = "black")
lines(dat$DateTime, dat$Sub_metering_2, col = "red")
lines(dat$DateTime, dat$Sub_metering_3, col = "blue")
legend("topright",
col = c("black", "red", "blue"),
legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
lty = c(1,1,1))
# Plot 4
plot(dat$DateTime, dat$Global_reactive_power,
type = "l",
xlab = "datetime", ylab = "Global_reactive_power")
dev.off()