forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot4.R
More file actions
21 lines (20 loc) · 993 Bytes
/
plot4.R
File metadata and controls
21 lines (20 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
library(data.table)
library(lubridate)
library(dplyr)
temp <- read.table("household_power_consumption.txt", header=TRUE, sep= ";", na.strings = c("?",""))
temp$Date<-dmy(temp$Date)
df<- temp[year(temp$Date)== 2007 & month(temp$Date)==2 & mday(temp$Date) <3,]
rm(temp)
df$datetime <- paste(df$Date,df$Time)
df$Time <- strptime(df$datetime, format = "%Y-%m-%d %H:%M:%S")
df<-tbl_df(df[,1:9])
png(filename="plot4.png",width=480,height=480,units="px")
par(mfrow=c(2,2))
with(df,plot(Time,Global_active_power,type="l",ylab="Global Active Power",xlab=""))
with(df,plot(Time,Voltage,type="l",xlab="datetime"))
with(df,plot(Time,Sub_metering_1,type="l",ylab="Energy sub metering",xlab=""))
lines(df$Time,df$Sub_metering_2,col="red",type="l")
lines(df$Time,df$Sub_metering_3,col="blue",type="l")
legend("topright",legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),lty=c(1,1,1),col=c("black","red","blue"),bty="n")
with(df,plot(Time,Global_reactive_power,type="l",xlab="datetime"))
dev.off()