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 (15 loc) · 653 Bytes
/
Copy pathplot2.R
File metadata and controls
21 lines (15 loc) · 653 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
## Getting dataset with fread from data.table package
data <- fread("./Data/household_power_consumption.txt", na.strings = "?")
## Converting classes
data$Date <- as.Date(data$Date, format = "%d/%m/%Y")
data$Global_active_power <- as.numeric(data$Global_active_power)
## Subsetting the data
data <- data[Date == "2007/02/01" | Date == "2007/02/02" ]
## Adding and converting new variables
data[,DateTime:=as.POSIXct(paste(data$Date, data$Time))]
## Plot
plot(data$DateTime, data$Global_active_power, type="l",
ylab="Global Active Power (kilowatts)", xlab="")
## Saving to file
dev.copy(png, file="plot2.png", height=480, width=480)
dev.off()