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
24 lines (18 loc) · 1.04 KB
/
plot1.R
File metadata and controls
24 lines (18 loc) · 1.04 KB
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(data.table)
#read data from zip file
consumption <- read.table(unz("./household_power_consumption.zip","household_power_consumption.txt"),
header=TRUE, na.strings = "?", sep = ";",
stringsAsFactors = FALSE)
#convert date and time columns to a combined dateTime so we can subset
consumption$DateTime <- paste(consumption$Date, consumption$Time)
consumption$DateTime <- strptime(consumption$DateTime, format = "%d/%m/%Y %H:%M:%S")
#get data of interest (2007-02-01 and 2007-02-02)
lowDate <- strptime("01/02/2007 00:00:00", format = "%d/%m/%Y %H:%M:%S")
highDate <- strptime("03/02/2007 00:00:00", format = "%d/%m/%Y %H:%M:%S")
consumptionOfInterest <- subset(consumption, DateTime >= lowDate
& DateTime < highDate)
#Create plot as png
png(filename = "plot1.png", width = 480, height = 480)
with(consumptionOfInterest, hist(Global_active_power, col="red", main="Global Active Power",
xlab="Global Active Power (kilowatts)"))
dev.off()