forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3.R
More file actions
61 lines (46 loc) · 1.74 KB
/
Copy pathplot3.R
File metadata and controls
61 lines (46 loc) · 1.74 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
49
50
51
52
53
54
55
56
57
58
59
60
61
setwd("~/ExData_Plotting1")
downloadURL <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
if (!dir.exists("Data")) {
dir.create("Data")
}
downloadFile <- "./Data/household_power_consumption.zip"
householdFile <- "./Data/household_power_consumption.txt"
if (!file.exists(householdFile)) {
download.file(downloadURL, downloadFile, method = "curl", mode = "wb")
unzip(downloadFile, overwrite = TRUE, exdir = "./Data")
}
plotData <- read.table(
householdFile,
header = TRUE,
sep = ";",
na.strings = "?",
stringsAsFactors = FALSE
)
finalData <- plotData[plotData$Date %in% c("1/2/2007", "2/2/2007"), ]
SetTime <- strptime(
paste(finalData$Date, finalData$Time, sep = " "),
"%d/%m/%Y %H:%M:%S"
)
finalData <- cbind(SetTime, finalData)
columnlines <- c("black", "red", "blue") labels <- c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3") plot(finalData$SetTime, finalData$Sub_metering_1, type="l", col=columnlines[1], xlab="", ylab="Energy sub metering") lines(finalData$SetTime, finalData$Sub_metering_2, col=columnlines[2]) lines(finalData$SetTime, finalData$Sub_metering_3, col=columnlines[3]) legend("topright", legend=labels, col=columnlines, lty="solid")
png("plot3.png", width = 480, height = 480)
columnlines <- c("black", "red", "blue")
labels <- c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3")
plot(
finalData$SetTime,
finalData$Sub_metering_1,
type = "l",
col = columnlines[1],
xlab = "",
ylab = "Energy sub metering"
)
lines(finalData$SetTime, finalData$Sub_metering_2, col = columnlines[2])
lines(finalData$SetTime, finalData$Sub_metering_3, col = columnlines[3])
legend(
"topright",
legend = labels,
col = columnlines,
lty = 1
)
dev.off()
file.exists("plot3.png")