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
48 lines (34 loc) · 1.21 KB
/
Copy pathplot4.R
File metadata and controls
48 lines (34 loc) · 1.21 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
36
37
38
39
40
41
42
43
44
45
46
47
48
# Check if we have data, if not load it!
source("load.data.R")
if (!exists("metering.data") || nrow(metering.data) == 0) {
metering.data <- load.data()
}
# Plot to screen
par(mfrow=c(2,2))
#1
plot(metering.data$DateTime, metering.data$Global_active_power,
type="l", xlab="", ylab="Global Active Power")
#2
plot(metering.data$DateTime, metering.data$Voltage,
type="l", xlab="datetime", ylab="Voltage")
#3
with(metering.data, {
plot(x = DateTime, y = Sub_metering_1,
type = "l", col = "black",
xlab = "", ylab = "Energy sub metering")
lines(x = DateTime, y = Sub_metering_2, col = "red")
lines(x = DateTime, y = Sub_metering_3, col = "blue")
})
legend("topright", lty = 1,
col = c("black", "red", "blue"),
legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
text.width = strwidth("Sub_metering_1"),
cex=0.7,
bty = "n")
#4
plot(metering.data$DateTime, metering.data$Global_reactive_power,
type="l", xlab="datetime", ylab="Global_reactive_power")
# Save to PNG file with a width of 480 pixels and a height of 480 pixels.
dev <- dev.cur()
dev.copy(png, filename = "plot4.png", width = 480, height = 480)
dev.off()