forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3.R
More file actions
35 lines (30 loc) · 698 Bytes
/
plot3.R
File metadata and controls
35 lines (30 loc) · 698 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
32
33
34
35
# Read the data.
d <- read.csv(
"household_power_consumption.txt",
sep=";",
stringsAsFactors=F,
na.strings=c("?")
)
# Subset on dates.
d <- d[d$Date %in% c("1/2/2007", "2/2/2007"),]
d$DateTime <- # Add new date-time column.
strptime(paste(d$Date, d$Time), format="%d/%m/%Y %H:%M:%S", tz="UTC")
# Plot
png("plot3.png")
plot(
x = d$DateTime,
y = d$Sub_metering_1,
type = "l",
xlab = "",
ylab = "Energy sub metering"
)
lines(d$DateTime, d$Sub_metering_2, col = "red")
lines(d$DateTime, d$Sub_metering_3, col = "blue")
legend(
"topright",
col = c("black","red","blue"),
c("Sub_metering_1","Sub_metering_2", "Sub_metering_3"),
lty = c(1,1),
lwd = c(1,1)
)
dev.off()