forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot2.R
35 lines (27 loc) · 948 Bytes
/
plot2.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
32
33
34
35
DATASET_DIR <- "data"
DATASET_URL <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
DATASET_FILE <- file.path(DATASET_DIR, "household_power_consumption.txt")
source("download_data.R")
download_dataset(DATASET_URL, DATASET_FILE, DATASET_DIR)
power_consumption <- read.csv(
DATASET_FILE,
sep = ";",
as.is = TRUE,
na.strings = "?"
)
power_consumption$datetime <- strptime(
paste(power_consumption$Date, power_consumption$Time),
format = "%d/%m/%Y %H:%M:%S",
tz = "GMT"
)
power_consumption$Date <- as.Date(power_consumption$Date, format = "%d/%m/%Y")
power_consumption <- subset(power_consumption, Date %in% as.Date(c("2007-02-01", "2007-02-02")))
png("plot2.png", width = 480, height = 480)
with(power_consumption, plot(
datetime, Global_active_power,
type = "l",
xlab = "",
ylab = "Global Active Power (kilowatts)"
))
dev.off()
message("Created plot2.png")