forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot2.R
36 lines (25 loc) · 1.08 KB
/
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
36
### Peer-graded Assignment: Course Project 1
### plot2.R
### installing and/or loading "data.table" package
if (!"data.table" %in% installed.packages()) {install.packages("data.table")}
library(data.table)
### download the dataset
fileUrl <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download.file(fileUrl,destfile="./Dataset.zip")
### unzip the dataset
unzip(zipfile="./Dataset.zip")
### load the dataset (missing values are coded as '?')
dt <- fread(input = "household_power_consumption.txt"
, na.strings="?")
### Create a DateTimeClasses POSIXct column
dt[, datetime := as.POSIXct(paste(Date, Time), format = "%d/%m/%Y %H:%M:%S")]
### Extract from the dates 2007-02-01 and 2007-02-02
dt <- dt[(datetime >= "2007-02-01") & (datetime < "2007-02-03")]
### Start the PNG bitmap device
png("plot2.png", width=480, height=480)
### Plot 2
plot(x = dt[, datetime]
, y = dt[, Global_active_power]
, type="l", xlab="", ylab="Global Active Power (kilowatts)")
### Turn off the device
dev.off()