forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
27 lines (26 loc) · 1005 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
zipFile = "./data/household_power_consumption.zip"
txtFile = "./data/household_power_consumption.txt"
if(!file.exists(txtFile)) {
url="https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
file<-download.file(url, destfile = zipFile, method = "curl")
unzip(zipFile,exdir="./data/")
}
df<-read.table(txtFile,sep=';',na.strings="?",header=TRUE)
twoDaysData<-df[df$Date=="1/2/2007"|df$Date=="2/2/2007",]
twoDaysData$DateTime<-as.POSIXct(strptime(paste(twoDaysData$Date,twoDaysData$Time),format='%d/%m/%Y %H:%M:%S'))
png(file="Plot3.png")
plot(x=twoDaysData$DateTime,
y=twoDaysData$Sub_metering_1,
ylab="Energy sub metering",
xlab="",
type="l",
col="black"
)
lines(x=twoDaysData$DateTime,y=twoDaysData$Sub_metering_2,col='red')
lines(x=twoDaysData$DateTime,y=twoDaysData$Sub_metering_3,col='blue')
legend("topright",
c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),
col=c('black','red','blue'),
lty=c(1,1)
)
dev.off()