forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot3.R
25 lines (20 loc) · 1.28 KB
/
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
# Read the data
download.file(url = "https://d396qusza40orc.cloudfront.net/exdata/data/household_power_consumption.zip" , destfile = "household_power_consumption.zip", method="curl")
unzip("household_power_consumption.zip")
dados <- read.table("household_power_consumption.txt", header= TRUE, sep= ";", na.strings="?", colClasses = c("character", "character", "numeric", "numeric","numeric","numeric","numeric","numeric"))
dados2 <- dados[as.Date(dados$Date, format="%d/%m/%Y") >= "2007-02-01" & as.Date(dados$Date, format="%d/%m/%Y") <= "2007-02-02", ]
#Parse the data time characters
for (i in seq_along(dados2[,1])){
data <- dados2[i, "Date"]
hora <- dados2[i, "Time"]
data_hora <- paste(data, hora)
res <- strptime(data_hora, "%d/%m/%Y %H:%M:%S")
dados2[i, "date_time"] <- as.POSIXct(res)
}
png(filename = "plot3.png", width = 480, height = 480)
plot(Sub_metering_1 ~ date_time, dados2, type="l", xaxt="n", ylab="Energy submetering", xlab="", col="black")
lines(Sub_metering_2 ~ date_time, dados2, col="red")
lines(Sub_metering_3 ~ date_time, dados2, col="blue")
legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty=c(1,1), col=c("black", "red","blue"))
axis(1, at= quantile(dados2$date_time , probs=c(0, 0.5 , 1)), label=c("Thu", "Fri", "Sat") )
dev.off()