-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
21 lines (17 loc) · 933 Bytes
/
plot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#plot3
#Author: Haibin Li
#Email:[email protected]
#Date:07-18-2016
setwd("C:\\Users\\lhb-pc\\Desktop\\RCourse\\EDA\\RClass\\exdata_data_household_power_consumption")
data <- read.table("household_power_consumption.txt",sep=";",header=T,na.strings="?")
data$Time <- strptime(paste(data$Date, data$Time, sep=" "),"%d/%m/%Y %H:%M:%S")
data$Date <- as.Date(data$Date, format = "%d/%m/%Y")
total <- subset(data,Date==as.Date("2007/02/01")|Date==as.Date("2007/02/02"))
Sys.setlocale("LC_TIME","English")
attach(total)
png("plot3.png", width=480, height=480)
plot(Time, as.numeric(Sub_metering_1), type="l", col = "black", ylab="Energy sub metering", xlab="")
lines(Time, as.numeric(Sub_metering_2), type="l", col = "red")
lines(Time, as.numeric(Sub_metering_3), type="l", col = "blue")
legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), pch = 1, col = c("black","red", "blue"))
dev.off()