forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot2.R
23 lines (16 loc) · 762 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
#load data.table library
library("data.table")
# Read file
householdEPC <- data.table::fread(input = "../data/household_power_consumption.txt", na.strings="?")
# Convert values to numeric
householdEPC[, Global_active_power := lapply(.SD, as.numeric), .SDcols = c("Global_active_power")]
#Convert to POSIXct to use week days
householdEPC[, dateTime := as.POSIXct(paste(Date, Time), format = "%d/%m/%Y %H:%M:%S")]
# Subset observations from 2007-02-01 to 2007-02-02
householdEPC <- householdEPC[(dateTime >= "2007-02-01") & (dateTime < "2007-02-03")]
png("plot2.png", width=480, height=480)
## Plot 2
plot(x = householdEPC[, dateTime]
, y = householdEPC[, Global_active_power]
, type="l", xlab="", ylab="Global Active Power (kilowatts)")
dev.off()