forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot1.R
22 lines (19 loc) · 783 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
# Read in Data File
df = "household_power_consumption.txt"
hpc<-read.delim(df, header=T, sep=";", na.strings="?")
# Convert date/times into datetime format and select subset of data to work with
hpc$datetime = strptime(paste(hpc$Date,hpc$Time), format="%d/%m/%Y %H:%M:%S")
sd = strptime("01/02/2007 00:00:00", format="%d/%m/%Y %H:%M:%S")
ed = strptime("03/02/2007 00:00:00", format="%d/%m/%Y %H:%M:%S")
twoDays<-subset(hpc, datetime>=sd & datetime<ed, select=3:10)
# View updated stats
summary(twoDays)
str(twoDays)
# Plot #1 - Historgram of Power Usage by kilowatts
png(filename="plot1.png", width=480, height=480)
hist(twoDays$Global_active_power,
xlab="Global Active Power (kilowatts)",
ylab="Frequency",
main="Global Active Power",
col="red")
dev.off()