forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3.R
More file actions
19 lines (19 loc) · 1.07 KB
/
Copy pathplot3.R
File metadata and controls
19 lines (19 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
setwd("~/projects/coursera/data_science/04-exdata-035")
fileName = "household_power_consumption.txt"
# grep "^12/2/2007" household_power_consumption.txt -n -m 1
# 66638
# grep "^[12]/2/2007" household_power_consumption.txt | wc -l
# 2880
dataHeader = read.csv2(fileName, nrows = 1, header = F, sep = ";", stringsAsFactors = F)
dataTable = read.csv2(fileName, skip = 66637, nrow = 2880, sep = ";", stringsAsFactors = F, dec = ".")
colnames(dataTable) = dataHeader
#
Sys.setlocale("LC_TIME", "en_US.UTF-8")
dataTable$Date = as.Date(dataTable$Date, format="%d/%m/%Y")
dataTable$Timestamp = strptime(paste(dataTable$Date, dataTable$Time), "%Y-%m-%d %H:%M:%S")
plot(dataTable$Timestamp, dataTable$Sub_metering_1, type="l", xlab="", ylab="Energy Submetering")
lines(dataTable$Timestamp, dataTable$Sub_metering_2, type="l", col="red")
lines(dataTable$Timestamp, dataTable$Sub_metering_3, type="l", col="blue")
legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty=1, lwd=2.5, col=c("black", "red", "blue"))
dev.copy(png, file="plot3.png", width=480, height=480)
dev.off()