forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot3.R
29 lines (28 loc) · 929 Bytes
/
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
InData<-read.table("household_power_consumption.txt",
header = TRUE,
sep=";",
na.strings=c("?"))
InData <- InData[ which(InData$Date=="1/2/2007"
| InData$Date=="2/2/2007"), ]
InData$DT <- strptime(paste(InData$Date, InData$Time), "%d/%m/%Y %H:%M:%S")
## Plot 3
plot(InData$DT,InData$Sub_metering_1,
type="l",
xlab= NA,
ylab="Energy sum metering"
)
# add line 2
lines(InData$DT,InData$Sub_metering_2,
type="l",
col="red")
# add line 3
lines(InData$DT,InData$Sub_metering_3,
type="l",
col="blue")
# add a legend
legend("topright",
c("Sub_metering_1","Sub_metering_2", "Sub_metering_3"), # puts text in the legend
lty=c(1,1), # gives the legend appropriate symbols (lines)
lwd=c(1,1),col=c("black","red", "blue"), # gives the legend lines the correct color and width
cex=.75
)