forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
49 lines (46 loc) · 1.14 KB
/
plot3.R
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
tbldata <- read.table("household_power_consumption.txt",
header=FALSE,
sep=";",
na.strings="?",
col.names=c("Date","Time","Global_active_power","Global_reactive_power","Voltage","Global_intensity","Sub_metering_1","Sub_metering_2","Sub_metering_3"),
skip=66637,
nrows=2880
)
png(filename="plot3.png",
width=480,
height=480,
unit="px",
)
plot(
x= strptime(
paste(tbldata$Date, tbldata$Time)
, format="%d/%m/%Y %H:%M:%S"
),
y=tbldata$Sub_metering_1,
type="l",
ylab="Energy sub metering",
xlab=""
)
lines(
x= strptime(
paste(tbldata$Date, tbldata$Time)
, format="%d/%m/%Y %H:%M:%S"
),
y=tbldata$Sub_metering_2,
col="red"
)
lines(
x= strptime(
paste(tbldata$Date, tbldata$Time)
, format="%d/%m/%Y %H:%M:%S"
),
y=tbldata$Sub_metering_3,
col="blue"
)
legend(
x = "topright",
legend = c("Sub_metering_1","Sub_metering_2", "Sub_metering_3"),
col=c("black","red","blue"),
lty=1 #show lines
)
dev.off()