forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot2.R
More file actions
31 lines (22 loc) · 678 Bytes
/
plot2.R
File metadata and controls
31 lines (22 loc) · 678 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
29
30
31
#the text file "household_power_consumption.txt" should
#be downloaded and installed in the working directory
#before running
png(filename = "plot2.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")
plot(
t$DateTime,
t$Global_active_power,
type="n",
ylab="Global Active Power (kilowatts)",
xlab="")
lines(t$DateTime, t$Global_active_power)
dev.off()