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
29 lines (22 loc) · 858 Bytes
/
plot2.R
File metadata and controls
29 lines (22 loc) · 858 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
25
26
27
28
29
# load sqldf package for read.csv.sql function
library(sqldf)
# remember locale
lt <- Sys.getlocale("LC_TIME")
# set new locale
Sys.setlocale("LC_TIME", "C")
# the path to data set
filename <- "exdata-data-household_power_consumption/household_power_consumption.txt"
# SQL query, select rows for the first two days of February 2007
sql <- "select * from file where Date = '1/2/2007' or Date = '2/2/2007';"
# read selected rows
power <- read.csv.sql(filename, sep = ";", row.names = F, sql = sql)
# create Datetime column
power$Datetime <- as.POSIXlt(paste(power$Date, power$Time), format="%d/%m/%Y %H:%M:%S")
# plot
png("plot2.png", width=480, height=480, units="px")
par(bg=NA)
plot(power$Datetime, power$Global_active_power, type="l",
ylab="Global Active Power (kilowatts)", xlab="")
dev.off()
# restore locale
Sys.setlocale("LC_TIME", lt)