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
52 lines (49 loc) · 938 Bytes
/
plot3.R
File metadata and controls
52 lines (49 loc) · 938 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Read and setup data
data0 <- read.csv(
"household_power_consumption.txt" ,
sep=";" ,
na.strings="?"
)
data0$dt <- strptime(
paste( data0$Date , data0$Time ) ,
format="%d/%m/%Y %H:%M:%S"
)
data <- data0[
!is.na(data0$dt)
& data0$dt > strptime( "2007-01-31 23:59:00" , format="%Y-%m-%d %H:%M:%S" )
& data0$dt < strptime( "2007-02-03" , format="%Y-%m-%d" )
, ]
# Plot
png( filename="plot3.png" )
plot(
data$dt ,
data$Sub_metering_1 ,
type="l" ,
xlab="" ,
ylab="Energy sub metering"
)
lines(
data$dt ,
data$Sub_metering_2 ,
col="red"
)
lines(
data$dt ,
data$Sub_metering_3 ,
col="blue"
)
legend(
"topright" ,
legend=c(
"Sub_metering_1" ,
"Sub_metering_2" ,
"Sub_metering_3"
) ,
col=c(
"black" ,
"red" ,
"blue"
) ,
lty="solid"
)
dev.off()