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 (21 loc) · 659 Bytes
/
plot1.R
File metadata and controls
28 lines (21 loc) · 659 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
#the text file "household_power_consumption.txt" should
#be downloaded and installed in the working directory
#before running
png(filename = "plot1.png")
lines <- readLines("household_power_consumption.txt")
rows <- substr(lines, 0, 8) == "1/2/2007" | substr(lines, 0, 8) == "2/2/2007"
rows[1] = TRUE
data <- lines[rows]
t <- read.csv(
text = data,
na.strings = c("?"),
sep=";",
stringsAsFactors = FALSE)
t$DateTime <- strptime(paste(t$Date, t$Time), "%d/%m/%Y %H:%M:%S")
hist(
t$Global_active_power,
main="Global Active Power",
xlab="Global Active Power (kilowatts)",
ylab="Frequency",
col="red")
dev.off()