forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot1.R
31 lines (22 loc) · 850 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
23
24
25
26
27
28
29
30
31
loadData <- function(input = file.path("household_power_consumption.txt")) {
# read just header
header <- read.csv(input, nrows = 1, header = FALSE, sep =';', stringsAsFactors = FALSE)
# read data
electric.data <- read.csv(input, skip = 66636, nrows = 2880, na.strings = "?", sep =';')
# puts back header
colnames( electric.data ) <- unlist(header)
# inserts datetime
electric.data$DateTime <- strptime(paste(electric.data$Date, electric.data$Time), "%d/%m/%Y %H:%M:%S")
electric.data
}
createPlot1 <- function(data) {
# starts saving to file
png("plot1.png", width=480, height=480)
# generates histogram
hist(data$Global_active_power, xlab = "Global Active Power (kilowatts)",
main = "Global Active Power", col = "red")
# ends saving to file
dev.off()
}
data <- loadData()
createPlot1(data)