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
25 lines (18 loc) · 867 Bytes
/
Copy pathplot1.R
File metadata and controls
25 lines (18 loc) · 867 Bytes
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
# download data
#
dataFile <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
zipFileName <- "data/exdata_data_household_power_consumption.zip"
dataFileName <- "data/household_power_consumption.txt"
if (!dir.exists("data")) {
dir.create("data")
}
download.file(dataFile, destfile = zipFileName, method = "curl")
unzip(zipFileName, exdir = "data", overwrite = TRUE)
# Read only the rows for 2007-02-01 to 2007-02-02
heading <- read.table(dataFileName, nrow = 1, header = FALSE, sep = ";")
data <- read.table(dataFileName, skip = 66637, nrow = 69517-66637, header = FALSE, sep = ";")
names(data) <- heading[1,]
# plot histogram to a plot1.png
png("plot1.png", width = 480, height = 480)
hist(data$Global_active_power, col = "red", main = "Global Active Power", xlab = "Global Active Power (kilowatts)")
dev.off()