forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
31 lines (23 loc) · 855 Bytes
/
plot3.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
# 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(1,1))
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.9)
# Save to PNG file with a width of 480 pixels and a height of 480 pixels.
dev <- dev.cur()
dev.copy(png, filename = "plot3.png", width = 480, height = 480)
dev.off()