forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot1.R
More file actions
22 lines (17 loc) · 765 Bytes
/
plot1.R
File metadata and controls
22 lines (17 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# load sqldf package for read.csv.sql function
library(sqldf)
# 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("plot1.png", width=480, height=480, units="px")
par(bg=NA)
hist(power$Global_active_power, breaks=12, freq=T, col="red",
xlab="Global Active Power (kilowatts)", ylab="Frequency",
main="Global Active Power")
dev.off()