forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
14 lines (14 loc) · 856 Bytes
/
plot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
temp <- tempfile()
download.file("https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip",temp,method="curl")
data <- read.table(unz(temp,"household_power_consumption.txt"),header=TRUE,sep=";",na.strings="?",quote="")
data2 <- data[data$Date == "1/2/2007"|data$Date == "2/2/2007",]
DateTime <- paste(data2$Date,data2$Time)
data3 <- data.frame(data2,DateTime)
data3$DateTime <- strptime(data3$DateTime,"%d/%m/%Y %H:%M:%S")
png("plot3.png",width=480,height=480)
plot(data3$DateTime,data3$Sub_metering_1,xlab="",ylab="Energy sub metering",type="s")
points(data3$DateTime,data3$Sub_metering_2,xlab="",type="s",col="red")
points(data3$DateTime,data3$Sub_metering_3,xlab="",type="s",col="blue")
legend("topright",legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),lwd=2,col=c("black","red","blue"))
dev.off()
unlink(temp)