forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
31 lines (23 loc) · 873 Bytes
/
plot3.R
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
library('lubridate')
setwd("~/R/exdata-034/ExData_Plotting1")
df <- read.csv('./data/household_power_consumption.txt', sep = ";", na.strings = "?")
# Combine date and time fields into POSIXct datetime object
df$datetime <- dmy_hms(paste(df$Date, df$Time))
# subset data from the dates 2007-02-01 and 2007-02-02
data <- df[df$Date == "1/2/2007" | df$Date == "2/2/2007",]
# Plot 3: Energy sum metering over time
png('plot3.png', width = 480, height = 480)
par(mfrow=c(1,1))
plot(data$datetime, data$Sub_metering_1,
xlab = "",
ylab="Energy sub metering",
type="l")
lines(data$datetime, data$Sub_metering_2,
col="red")
lines(data$datetime, data$Sub_metering_3,
col="blue")
legend("topright",
legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
col = c("black", "red", "blue"),
lty = c(1, 1, 1))
dev.off()