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) · 1013 Bytes
/
Copy pathplot1.R
File metadata and controls
24 lines (18 loc) · 1013 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
## plot1()
##
## Purpose: Look at the frequency of global active power levels for two days in February
##
## Note: Assumes the dataset has already been unzipped and is sitting in the current working directory
plot1 <- function() {
## Read in the data
data <- read.table("household_power_consumption.txt", header = T, sep = ";", colClasses = c(NA, NA, "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric"), stringsAsFactors = F, na.strings = "?")
## Convert dates/times from character
data$Date <- as.Date(data$Date, format = "%d/%m/%Y")
data$Time <- strptime(data$Time, format = "%H:%M:%S")
## Restrict the dates to the first two days in February 2007
data <- data[(data$Date > "2007-01-31" & data$Date < "2007-02-03"), ]
## Plot the Global Active Power data, by frequency; generate PNG
png(filename = "plot1.png")
hist(data$Global_active_power, freq = T, main = "Global Active Power", xlab = "Global Active Power (kilowatts)", col = "red")
dev.off()
}