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
18 lines (18 loc) · 1.02 KB
/
plot3.R
File metadata and controls
18 lines (18 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
td = tempdir()
tf = tempfile(tmpdir=td, fileext=".zip")
download.file(url, tf)
fname = unzip(tf, list=TRUE)$Name[1]
unzip(tf, files=fname, exdir=td, overwrite=TRUE)
fpath = file.path(td, fname)
plotdata <- read.table(fpath, header = TRUE,sep=";",na.strings="?")
plotsubset <- subset(plotdata, plotdata$Date >= as.Date("2007-2-1","%Y-%m-%d") & plotdata$Date <= as.Date("2007-2-2","%Y-%m-%d"))
install.packages("chron")
library(chron)
dateandtime <- chron(as.character(plotsubset$Date),plotsubset$Time,format = c(dates = "Y-m-d", times = "h:m:s"))
plot(dateandtime,plotsubset$Sub_metering_1,type="l",ylab="Energy sub metering", xlab="")
lines(dateandtime,plotsubset$Sub_metering_2,col="red")
lines(dateandtime,plotsubset$Sub_metering_3,col="blue")
legend("topright",col=c("black","red","blue"),legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),lwd = 0.5, cex = 0.8,lty = c(1, 1, 1), pch =c(NA,NA,NA))
dev.copy(png, file = "plot3.png")
dev.off()