forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot2.R
More file actions
21 lines (17 loc) · 703 Bytes
/
Copy pathplot2.R
File metadata and controls
21 lines (17 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
## library dplyr
plot2 <- function(x){
## Read the file and select relevant rows
hpc <- read.delim("household_power_consumption.txt", sep=";", na.strings = "?")
hpc_1 <- filter(hpc, Date == "1/2/2007")
hpc_2 <- filter(hpc, Date == "2/2/2007")
hpc <- rbind(hpc_1, hpc_2)
## Create datetime column as class "Date"
hpc$Date <- as.Date(hpc$Date, "%d/%m/%Y")
datetime <- paste(as.character(hpc$Date), as.character(hpc$Time))
datetime <- strptime(datetime, c("%Y-%m-%d%T"))
hpc <- cbind(hpc, datetime)
## Save plot to png file
png(file="plot2.png")
plot(hpc$datetime, hpc$Global_active_power, type = "l", xlab = "", ylab = "Gloabal Active Power (kilowatts)")
dev.off()
}