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
23 lines (21 loc) · 911 Bytes
/
plot3.R
File metadata and controls
23 lines (21 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
##Collect tools
library(data.table)
library(dplyr)
library(lubridate)
##Read data
power <- fread("household_power_consumption.txt", na.strings = '?'
,colClasses = list(character = 1:9))
power <- filter(power, Date == "1/2/2007" | Date == "2/2/2007")
power <- mutate(power, Timestamp = dmy(Date) + hms(Time))
power <- mutate_each(power, funs(as.numeric), -c(Date, Time, Timestamp))
power <- select(power, -Date, -Time)
##Print plot to PNG (480px is the default size)
png(filename = "plot3.png")
plot(power$Timestamp, power$Sub_metering_1, type = "l",
ylab = "Energy sub metering", xlab = "")
points(power$Timestamp, power$Sub_metering_2, type = "l", col = "red")
points(power$Timestamp, power$Sub_metering_3, type = "l", col = "blue")
legend(x = "topright",
legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
col = c("black", "red", "blue"), lwd = 1)
dev.off()