forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot3.R
26 lines (23 loc) · 994 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
get_data <- function() {
download.file("https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
, "household_power_consumption.zip", method = "wget", extra = "-c")
unzip("household_power_consumption.zip")
t <- read.csv("household_power_consumption.txt", header = TRUE, sep = ";"
, na.strings = "?")
t[t$Date == "1/2/2007" | t$Date == "2/2/2007", ]
}
x <- get_data()
x$DT <- strptime(paste(as.character(x$Date),as.character(x$Time), sep = " ")
, format = "%d/%m/%Y %H:%M:%S")
Sys.setlocale(category = "LC_ALL", locale = "en_US")
png("plot3.png", 480, 480)
plot(x$DT, x$Sub_metering_1, type = "n", xlab = ""
, ylab = "Energy sub metering")
lines(x$DT, x$Sub_metering_1, col = "black")
lines(x$DT, x$Sub_metering_2, col = "red")
lines(x$DT, x$Sub_metering_3, col = "blue")
legend("topright"
, legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3")
, col = c("black", "red", "blue")
, lty = 1)
dev.off()