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
28 lines (24 loc) · 1020 Bytes
/
plot1.R
File metadata and controls
28 lines (24 loc) · 1020 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
26
27
28
## This file is the solution for Course Proj 1
## Read the data content at dates 1 and 2/2/2007
# Use regular expression to search for the dates
# at the beginning of each line (^)
# and output the text (value = TRUE)
f <- readLines("household_power_consumption.txt")
dayMatch <- grep("^[1,2]/2/2007", f, value = TRUE)
# Combine the text with col names, set sep and na.string
# also set colClasses and nrows for efficient read
data <- read.table(text = c(f[1],dayMatch),
header = TRUE,
sep = ";",
na.strings = "?",
colClasses = c(rep("character", 2), rep("numeric", 7)),
nrows = length(dayMatch)+1)
data$Date <- as.Date(data$Date, "%d/%m/%Y")
# Plot 1
png(filename = "plot1.png",
width = 480, height = 480, units = "px")
with(data, hist(Global_active_power,
col = "red",
main = "Global Active Power",
xlab = "Global Active Power (kilowatts)"))
dev.off()