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
22 lines (16 loc) · 640 Bytes
/
plot2.R
File metadata and controls
22 lines (16 loc) · 640 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Fetch "household_power_consumption.txt"
source("get_data.R")
# Read data.
data <- read.table("household_power_consumption.txt", sep = ";", header = TRUE, na.strings = "?")
# Fix Date datatype.
library(lubridate)
data$Datetime <- dmy_hms(paste(data$Date, ' ', data$Time))
data$Date <- dmy(data$Date)
# Subset with Date.
data <- data[which(data$Date >= as.Date("2007-02-01", "%Y-%m-%d") & data$Date <= as.Date("2007-02-02", "%Y-%m-%d")),]
# Get the device.
png(file = "plot2.png")
# The plot.
plot(data$Datetime, data$Global_active_power, type = 'l', xlab = "", ylab = "Global Active Power (kilowatts)")
# Close the device.
dev.off()