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 (16 loc) · 739 Bytes
/
plot1.R
File metadata and controls
22 lines (16 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# read in the data
txt_filename <- "household_power_consumption.txt"
if(!file.exists(txt_filename)) {
zip_filename <- "household_power_consumption.zip"
download.file("http://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip", zip_filename)
unzip(zip_filename)
}
data <- read.table(txt_filename, sep=";", header=TRUE, na.strings="?")
# filter down to the requested days
filtered_data <- data[data$Date=="1/2/2007" | data$Date=="2/2/2007",]
# start png
png(file="plot1.png", width=480, height=480, units="px")
# create histogram
hist(filtered_data$Global_active_power, main="Global Active Power", xlab="Global Active Power (kilowatts)", ylab="Frequency", col="red")
# close and enjoy!
dev.off()