forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot1.R
26 lines (23 loc) · 1000 Bytes
/
plot1.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
## the data should be in working directory in the
# "household_power_comsumption.txt"
# Set of scripts do make plots accrording to task in
# Exploratory Data Analysis Coursera course
# With script names corresponding to output .png files.
# read data
padata <- read.table("household_power_consumption.txt", na.strings = "?",
sep = ";", dec = ".", header = TRUE,
colClasses = c(rep("character", 2), rep("numeric",7)))
padata$Date <- as.Date(padata$Date, format = "%d/%m/%Y")
# filter date
padataf <- padata[padata$Date == as.Date("2007-02-01")|
padata$Date == as.Date("2007-02-02"),]
# combine date and time into single posix
padataf$DT <- strptime(paste(sep = " ", padataf$Date, padataf$Time),
format = "%Y-%m-%d %H:%M:%S")
# write png plot
png(file = "plot1.png")
hist(padataf$Global_active_power, col = "red",
main = "Global Active Power",
xlab = "Global Active Power (kilowatts)")
# close file
dev.off()