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
17 lines (12 loc) · 778 Bytes
/
plot1.R
File metadata and controls
17 lines (12 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
download.file("http://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip", "power.zip");
hhAll <- read.table(unz("power.zip", "household_power_consumption.txt"), sep=";", header=TRUE, na.strings="?", stringsAsFactors=FALSE);
datetime <- paste(hhAll$Date, hhAll$Time);
strptime(datetime, "%d/%m/%Y %H:%M:%S");
hhAll$datetime <- datetime;
hhAll$Date <- as.Date(hhAll$Date, format="%d/%m/%Y");
tgtDates <- as.Date(c('01/02/2007', '02/02/2007'), format="%d/%m/%Y");
hh <- with(hhAll, subset(hhAll, Date %in% tgtDates));
hh$datetime <- as.POSIXlt(hh$datetime, format="%d/%m/%Y %H:%M:%S");
png("plot1.png", width=480, height=480);
hist(hh$Global_active_power, xlab="Global Active Power (kilowatts)", main="Global Active Power", col="red");
dev.off();