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
17 lines (15 loc) · 899 Bytes
/
plot2.R
File metadata and controls
17 lines (15 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Sys.setlocale(locale="English_United States.1252")
library(data.table)
all <- fread('household_power_consumption.txt', na.strings=c("?"), colClasses=c('character', 'character', rep('numeric',7)))
## create a subset for the given 2 days
days <- subset(all, all$Date == '1/2/2007' | all$Date == '2/2/2007')
## add a column consisting of the date and time to create a single datetime entry
days$when <- paste(days$Date, days$Time)
## convert the date time.
days$when <- as.POSIXct(strptime(paste(days$Date, days$Time), format='%d/%m/%Y %H:%M:%S'))
## for some reason the numerics were still converted to characters even with na.strings attributes
## so cast the values to numerics
days$Global_active_power <- as.numeric(days$Global_active_power)
png("plot2.png", width = 480, height = 480)
plot(days$Global_active_power ~ days$when, type='l', xlab='', ylab='Gobal Active Power (kilowatts)')
dev.off()