forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot2.R
22 lines (17 loc) · 1.07 KB
/
plot2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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 = "plot2.png", width = 480, height = 480)
plot(Global_active_power ~ date_time, dados2, type="l", xaxt="n", ylab="Global Active Power (Kilowatts)", xlab="")
axis(1, at= quantile(dados2$date_time , probs=c(0, 0.5 , 1)), label=c("Thu", "Fri", "Sat") )
dev.off()