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
12 lines (11 loc) · 777 Bytes
/
plot3.R
File metadata and controls
12 lines (11 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
library(RSQLite)
con<-dbConnect("SQLite", dbname="sample_db.sqlite")
dbWriteTable(con, name="sample_table", value="household_power_consumption.txt", row.names=FALSE, header=TRUE, sep=";")
mydata3<-dbGetQuery(con, "SELECT * FROM sample_table where Date='1/2/2007' or Date='2/2/2007'")
mydata3$PTime<-as.POSIXct(strptime(paste(mydata3$Date, mydata3$Time),"%d/%m/%Y %H:%M:%S"))
png(filename = "plot3.png")
plot(x=mydata3$PTime,y=mydata3$Sub_metering_1,type="l", xlab="",ylab="Energy Sub Metering")
lines(x=mydata3$PTime,y=mydata3$Sub_metering_2, type="l",col="red")
lines(x=mydata3$PTime,y=mydata3$Sub_metering_3, type="l",col="blue")
legend("topright",c("Sub Metering 1","Sub Metering 2", "Sub Metering 3"),lty=c(1,1,1),lwd=c(2.5,2.5,2.5),col=c("black","blue","red"))
dev.off()