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
27 lines (26 loc) · 1.12 KB
/
Copy pathplot3.R
File metadata and controls
27 lines (26 loc) · 1.12 KB
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
27
plot3 <- function(pathToDataFile) {
data <- readData(pathToDataFile)
png(file = "plot3.PNG")
par(mar = c(4,4,4,2))
plot(data$Sub_metering_1, main = NULL,
ylab = "Energy sub metering", xlab = "",
col = "black", type = "n", axes = FALSE, frame = TRUE)
lines(data$Sub_metering_1, col = "black")
lines(data$Sub_metering_2, col = "red")
lines(data$Sub_metering_3, col = "blue")
axis(side = 1, labels = c("Thu", "Fri", "Sat"),
at = c(1, floor(nrow(data)/2), nrow(data)))
axis(2)
legend("topright", lwd = 1, col = c("black", "red", "blue"),
legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
dev.off()
}
readData <- function(pathToDataFile) {
completeFileName = paste0(pathToDataFile, "/household_power_consumption.txt")
fullData <- read.csv(completeFileName, sep = ";",
na.strings = "?",
colClasses=c(rep("character",2), rep("numeric",7)))
fullData$Date = as.Date(fullData$Date, format = "%d/%m/%Y")
myData <- subset(fullData, Date >= "2007-02-01" & Date <= "2007-02-02" )
myData
}