forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
16 lines (11 loc) · 913 Bytes
/
plot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# load data
data <- read.table("household_power_consumption.txt", header=TRUE, sep=";", na.strings="?")
# filter data
shortdata <- subset(data,as.Date(data$Date,format="%d/%m/%Y") >= as.Date("2007-02-01") & as.Date(data$Date,format="%d/%m/%Y") <= as.Date("2007-02-02"))
# draw histogram
png(filename="plot3.png",width=480,height=480,units="px")
plot(strptime(as.character(paste(shortdata$Date,shortdata$Time)), format="%d/%m/%Y %H:%M:%S"),shortdata$Sub_metering_1, type="l",xlab="",ylab="Energy sub metering")
lines(strptime(as.character(paste(shortdata$Date,shortdata$Time)), format="%d/%m/%Y %H:%M:%S"),shortdata$Sub_metering_2,col="red")
lines(strptime(as.character(paste(shortdata$Date,shortdata$Time)), format="%d/%m/%Y %H:%M:%S"),shortdata$Sub_metering_3,col="blue")
legend("topright", "(x,y)",c("Sub_metering_1", "Sub_metering_2","Sub_metering_3"), lty=1, col = c("black","blue","red"))
dev.off()