forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot2.R
More file actions
49 lines (36 loc) · 1.13 KB
/
Copy pathplot2.R
File metadata and controls
49 lines (36 loc) · 1.13 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
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)
plot(finalData$SetTime, finalData$Global_active_power, type="l", col="black", xlab="", ylab="Global Active Power (kilowatts)")
png("plot2.png", width = 480, height = 480)
plot(
finalData$SetTime,
finalData$Global_active_power,
type = "l",
col = "black",
xlab = "",
ylab = "Global Active Power (kilowatts)"
)
dev.off()
file.exists("plot2.png")