forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot3.R
30 lines (23 loc) · 967 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
# Clear all variables
rm(list = ls())
#Read the data
data <- read.table("household_power_consumption.txt", header = T,
sep = ";", na.strings = "?")
#Convert the date to Date class for subsetting
data$Date <- as.Date(data$Date, format = "%d/%m/%Y")
#Subset the Data
data <- subset(data, subset = (Date >= "2007-02-01" & Date <= "2007-02-02"))
#Date and Time Conversion
data$datetime <- strptime(paste(data$Date, data$Time), "%Y-%m-%d %H:%M:%S")
# Plot 3
data$datetime <- as.POSIXct(data$datetime)
attach(data)
plot(Sub_metering_1 ~ datetime, type = "l",
ylab = "Energy sub metering", xlab = "")
lines(Sub_metering_2 ~ datetime, col = "Red")
lines(Sub_metering_3 ~ datetime, col = "Blue")
legend("topright", lty = 1, col = c("black", "red", "blue"),
legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
dev.copy(png, file = "plot3.png", height = 480, width = 480)
dev.off()
detach(data)