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
32 lines (26 loc) · 985 Bytes
/
plot3.R
File metadata and controls
32 lines (26 loc) · 985 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
27
28
29
30
31
32
library(dplyr)
library(lubridate)
#
dt <- tbl_df(read.csv2("household_power_consumption.txt", header = FALSE, dec=".", colClasses=c("character", "character", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric"), na.strings = "?", skip=66637, nrows=2880))
names(dt) = c("Date",
"Time",
"Global_active_power",
"Global_reactive_power",
"Voltage",
"Global_intensity",
"Sub_metering_1",
"Sub_metering_2",
"Sub_metering_3")
dt <- mutate(dt, datetime = parse_date_time(paste(Date,Time), "dmyHMS"))
png(filename="plot3.png", width=480, height=480,bg = "transparent")
with(dt, {
plot(datetime, Sub_metering_1, type="n", ylab="Energy sub metering", xlab="")
lines(datetime, Sub_metering_1, col="black")
lines(datetime, Sub_metering_2,col="red")
lines(datetime, Sub_metering_3,col="blue")
legend("topright", col=c("black","red","blue"),
legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),
lty="solid")
}
)
dev.off()