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
24 lines (19 loc) · 701 Bytes
/
plot2.R
File metadata and controls
24 lines (19 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library(sqldf)
# read data from file
hpc <- read.csv.sql("../data/household_power_consumption.txt", sep=";",
sql="SELECT *
FROM file
WHERE Date IN ('1/2/2007','2/2/2007')")
#convert ?'s to NA's
hpc[hpc=="?"]=NA
# add datetime column
hpc$DateTime <- as.POSIXct(paste(hpc$Date, hpc$Time),
format="%d/%m/%Y %H:%M:%S")
# create plot
with(hpc, plot(DateTime, Global_active_power,
type="l",
ylab="Global Active Power (kilowatts)",
xlab=""))
# save graphic to file
dev.copy(png, filename="plot2.png", width=480, height=480)
dev.off()