forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
21 lines (19 loc) · 833 Bytes
/
plot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
prepareFile <- function(filename){
require(sqldf) # install.packages("sqldf") if missing
df <- read.csv.sql(file = filename,header = TRUE, sql = "select * from file where Date='1/2/2007' or Date='2/2/2007'",sep=";")
df[,10] <- paste(df$Date,df$Time,sep=' ')
dates <- strptime(df[,10],"%d/%m/%Y %H:%M:%S")
df$fulldate = dates
df
}
generatePlot3<- function(df){
plot(x=df$fulldate,y=df$Sub_metering_1, type="n",ylab = "Energy sub metering", xlab = '')
lines(df$fulldate,df$Sub_metering_1,col="Black")
lines(df$fulldate,df$Sub_metering_2,col="Red")
lines(df$fulldate,df$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))
}
df <- prepareFile("household_power_consumption.txt")
png("plot3.png")
generatePlot3(df)
dev.off()