forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot2.R
28 lines (23 loc) · 1.02 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
# Week 1 'exploratory data analysis', plot 2
require(sqldf)
localFile <- "household_power_consumption.txt"
url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
destfile <- "household_power_consumption.zip"
if (!file.exists(localFile)){
download.file(url,destfile)
unzip(destfile)
unlink(destfile)
}
#read only the required dates (2007-02-01 and 2007-02-02)
library(sqldf)
inputData <- read.csv2.sql(localFile,
header=TRUE,
sep=";",
na.strings="?",
sql = "select * from file where Date = '1/2/2007' or Date = '2/2/2007'")
inputData$DateTime <- paste(inputData$Date,inputData$Time)
inputData$DateTime <- strptime(inputData$DateTime,format="%d/%m/%Y %H:%M:%S") #1/1/2007 00:01:00
inputData$Date <- as.Date(inputData$Date,format="%d/%m/%Y")
png("plot2.png",width=480,height=480)
with(inputData,plot(DateTime,Global_active_power,type="l",ylab="Global Active Power (kilowatts)"))
dev.off()