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
21 lines (15 loc) · 801 Bytes
/
plot3.R
File metadata and controls
21 lines (15 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#read only the "Date", "Time" and sub metering columns
d <- read.csv('household_power_consumption.txt',sep=';',na.strings="?",colClasses=c(NA, NA, rep("NULL",4),rep("numeric",3)))
#convert date
d$Date <- as.Date(d$Date, format="%d/%m/%Y")
#subsetting data
data <- d[d$Date>="2007-02-01" & d$Date<="2007-02-02",]
#merge date and time to a new column "Date_Time"
data$Date_Time <- as.POSIXct(paste(data$Date, data$Time))
#plot and save to file
png("plot3.png", height=480, width=480)
plot(data$Date_Time,data$Sub_metering_1,type="l",xlab="",ylab="Energy sub metering")
lines(data$Date_Time,data$Sub_metering_2,col="red")
lines(data$Date_Time,data$Sub_metering_3,col="blue")
legend("topright",lty=1,col=c("black","red","blue"),legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"))
dev.off()