This analysis looks at exploring energy consumption in households across two days: 1/2/2007 to 2/2/2007.
Frequency plot of power consumption levels.
suppressPackageStartupMessages(require(data.table))
data<-fread("household_power_consumption.txt")
data_feb <- subset(data, Date=="1/2/2007" | Date=="2/2/2007")
par(bg=NA)
hist(as.numeric(data_feb$Global_active_power),
col="red",main="Global Active Power",
xlab="Global Active Power (killowatts)")
z <- data.frame(dnt=strptime(paste(data_feb$Date,data_feb$Time,sep=" "),"%e/%m/%Y %H:%M:%S"),
power=as.numeric(data_feb$Global_active_power))
par(bg="NA")
plot(z$dnt,z$power,type="n",xlab="",ylab="Global Active Power (killowatts)")
lines(z$dnt,z$power)
z <- data.frame(dnt = strptime(paste(data_feb$Date,data_feb$Time,sep=" "),"%e/%m/%Y %H:%M:%S"),
sub1= as.numeric(data_feb$Sub_metering_1),
sub2= as.numeric(data_feb$Sub_metering_2),
sub3= as.numeric(data_feb$Sub_metering_3))
plot(z$dnt,z$sub1,type="n",xlab="",ylab="Energy sub metering")
legend("topright",
pch=c(NA,NA,NA),
col=c("black", "red", "blue"),
legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),
lwd=1, lty=c(1,1,1),
cex=1.0)
lines(z$dnt,z$sub1,col="black")
lines(z$dnt,z$sub2,col="red")
lines(z$dnt,z$sub3,col="blue")
This section will plot, in the following order: top row first, left to right:
z <- data.frame(dnt = strptime(paste(data_feb$Date,data_feb$Time,sep=" "),"%e/%m/%Y %H:%M:%S"),
power=as.numeric(data_feb$Global_active_power),
sub1= as.numeric(data_feb$Sub_metering_1),
sub2= as.numeric(data_feb$Sub_metering_2),
sub3= as.numeric(data_feb$Sub_metering_3),
volt=as.numeric(data_feb$Voltage),
powerre=as.numeric(data_feb$Global_reactive_power))
par(mfrow=c(2,2),bg="NA")
with(z,{
plot(z$dnt,z$power,type="n",xlab="",ylab="Global Active Power (killowatts)")
lines(z$dnt,z$power)
})
with(z,{
plot(z$dnt,z$volt,type="n",xlab="datetime",ylab="Voltage")
lines(z$dnt,z$volt)
})
with(z,{
plot(z$dnt,z$sub1,type="n",xlab="",ylab="Energy sub metering")
legend("topright",
pch=c(NA,NA,NA),
col=c("black", "red", "blue"),
legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),
lwd=1, lty=c(1,1,1),
bty="n")
lines(z$dnt,z$sub1,col="black")
lines(z$dnt,z$sub2,col="red")
lines(z$dnt,z$sub3,col="blue")
})
with(z,{
plot(z$dnt,z$powerre,type="n",xlab="datetime",ylab="Global_reactive_power")
lines(z$dnt,z$powerre)
})