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
26 lines (21 loc) · 718 Bytes
/
Copy pathplot2.R
File metadata and controls
26 lines (21 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# coursera exdata project 1 - plot 2
# read data ####
data <- read.table("household_power_consumption.txt",
header = TRUE, sep = ";",
na.strings = "?",
stringsAsFactors = FALSE,
nrows = 2075259)
# clean data ####
data <- data[(data$Date == "1/2/2007" | data$Date == "2/2/2007"), ]
str(data)
data$newdatetime <- strptime(paste(data$Date, data$Time),
format = "%d/%m/%Y %H:%M:%S")
str(data)
# generate plot 2 ####
plot(data$newdatetime,
data$Global_active_power, type = "l",
ylab = "Global Active Power (kilowatts)",
xlab = "",
main = "")
dev.copy(png, filename = "plot2.png")
dev.off()