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
35 lines (35 loc) · 1.03 KB
/
plot4.R
File metadata and controls
35 lines (35 loc) · 1.03 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
if (!"load_data.R" %in% list.files()) {
setwd("~/Desktop/Online Coursera/Coursera-Exploratory-Data-Analysis/ExData_Plotting1/")
}
source("load_data.R")
png(filename = "plot4.png",
width = 480, height = 480,
units = "px", bg = "transparent")
par(mfrow = c(2, 2))
## Top-left
plot(DateTime, Global_active_power,
type = "l",
xlab = "", ylab = "Global Active Power")
## Top-right
plot(DateTime, Voltage,
type = "l",
xlab = "datetime", ylab = "Voltage")
## Bottom-left
plot(DateTime, Sub_metering_1,
type = "l",
col = "black",
xlab = "", ylab = "Energy sub metering")
lines(DateTime, Sub_metering_2, col = "red")
lines(DateTime, Sub_metering_3, col = "blue")
# Remove the border of legend here.
legend("topright",
bty = "n",
col = c("black", "red", "blue"),
c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
lwd = 1)
## Bottom-right
plot(DateTime, Global_reactive_power,
type = "l",
col = "black",
xlab = "datetime", ylab = colnames(newData)[4])
dev.off()