loader

We are utilizing information from the UC Irvine Machine Learning Repository, a famous archive for AI datasets. Specifically, we will utilize the “Individual household electric power consumption Data Set”.

Description :

Measurements of electric power consumption in one household with a one-minute sampling rate over a period of almost 4 years. Different electrical quantities and some sub-metering values are available

Data Set :

https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip

The accompanying portrayals of the 9 factors in the dataset are taken from the UCI web site.

Data Set Information:

This archive contains 2075259 measurements gathered in a house located in Sceaux (7km of Paris, France) between December 2006 and November 2010 (47 months).
Notes:
1.(global_active_power*1000/60 – sub_metering_1 – sub_metering_2 – sub_metering_3) represents the active energy consumed every minute (in watt-hour) in the household by electrical equipment not measured in sub-metering 1, 2 and 3.
2. The dataset contains some missing values in the measurements (nearly 1,25% of the rows). All calendar timestamps are present in the dataset but for some timestamps, the measurement values are missing: a missing value is represented by the absence of value between two consecutive semi-colon attribute separators. For instance, the dataset shows missing values on April 28, 2007.

What We Will Do:

Our general objective here is basically to analyze how family unit vitality utilization differs over a 2-day time span in February 2007. We will reproduce the accompanying plots beneath, which were all developed utilizing the base plotting framework.

  1. Constructing the plot and spare it to a PNG record with a width of 480 pixels and a stature of 480 pixels.
  2. Naming every one of the plot records as ‘plot1.png’, ‘plot2.png’, and so on.
  3. Creating a different R code document (‘plot1.R’, ‘plot2.R’, and so on.) that builds the comparing plot, for example, code in ‘plot1.R’ develops the ‘plot1.png’ plot.

The four plots will look like this as an output:

1. Constructing the First Plot

################Reading the data########################
readfile<- read.table("household_power_consumption.txt",sep=";", header=T, stringsAsFactors=F,check.names=F, dec=".", na.strings="?",comment.char="", quote='\"')
###############Subsetiing Date####################
subsetDate <- subset(readfile, Date %in% c("1/2/2007","2/2/2007"))
##########converting the Date variables to Date classes############
subsetDate$Date <- as.Date(subsetDate$Date, format="%d/%m/%Y")
###########Converting Global_active_Power to numeric####
subsetDate$Global_active_power <- as.numeric(subsetDate$Global_active_power)
########Exporting Data as Png File in given size of 480X480####
png("plot1.png", width=480, height=480)
#############Plotting  the Data##############
hist(subsetDate$Global_active_power, main="Global Active Power",
     xlab="Global Active Power (kilowatts)", ylab="Frequency", col="Red")
dev.off()

Output:

2. Constructing 2nd Plot

################Reading the data########################
readfile<- read.table("household_power_consumption.txt",sep=";", header=T, stringsAsFactors=F,check.names=F, dec=".", na.strings="?",comment.char="", quote='\"')
###############Subsetiing Date####################
subsetDate <- subset(readfile, Date %in% c("1/2/2007","2/2/2007"))
##########converting the Date variables to Date classes############
subsetDate$Date <- as.Date(subsetDate$Date, format="%d/%m/%Y")
#########converting the Time variables to Time classes######
date_time <- paste(as.Date(subsetDate$Date),subsetDate$Time)
subsetDate$Datetime <- as.POSIXct(date_time)
###########Converting Global_active_Power to numeric####
subsetDate$Global_active_power <- as.numeric(subsetDate$Global_active_power)
########Exporting Data as Png File in given size of 480X480####
png("plot2.png", width=480, height=480)
#############Plotting  the Data##############
plot(subsetDate$Datetime,subsetDate$Global_active_power, type="l", xlab="", ylab="Global Active Power (kilowatts)")
dev.off()

Output:

3. Constructing 3rd Plot

################Reading the data########################
readfile<- read.table("household_power_consumption.txt",sep=";", header=T, stringsAsFactors=F,check.names=F, dec=".", na.strings="?",comment.char="", quote='\"')
###############Subsetiing Date####################
subsetDate <- subset(readfile, Date %in% c("1/2/2007","2/2/2007"))
##########converting the Date variables to Date classes############
subsetDate$Date <- as.Date(subsetDate$Date, format="%d/%m/%Y")
#########converting the Time variables to Time classes######
date_time <- paste(as.Date(subsetDate$Date),subsetDate$Time)
subsetDate$Datetime <- as.POSIXct(date_time)
###########Converting Global_active_Power,Sub_metering_1,Sub_metering_2.Sub_metering_3 to numeric####
subsetDate$Global_active_power <- as.numeric(subsetDate$Global_active_power)
subsetDate$Sub_metering_1 <- as.numeric(subsetDate$Sub_metering_1)
subsetDate$Sub_metering_2 <- as.numeric(subsetDate$Sub_metering_2)
subsetDate$Sub_metering_3 <- as.numeric(subsetDate$Sub_metering_3)
########Exporting Data as Png File in given size of 480X480####
png("plot3.png", width=480, height=480)
#############Plotting  the Data##############
plot(subsetDate$Datetime, subsetDate$Sub_metering_1, type="l", ylab="Energy Submetering", xlab="")
lines(subsetDate$Datetime, subsetDate$Sub_metering_2, type="l", col="red")
lines(subsetDate$Datetime, subsetDate$Sub_metering_3, type="l", col="blue")
legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty=1, lwd=2.5, col=c("black", "red", "blue"))
dev.off()

Output:

4. Constructing Final Plot

################Reading the data########################
readfile<- read.table("household_power_consumption.txt",sep=";", header=T, stringsAsFactors=F,check.names=F, dec=".", na.strings="?",comment.char="", quote='\"')
###############Subsetiing Date####################
subsetDate <- subset(readfile, Date %in% c("1/2/2007","2/2/2007"))
##########converting the Date variables to Date classes############
subsetDate$Date <- as.Date(subsetDate$Date, format="%d/%m/%Y")
#########converting the Time variables to Time classes######
date_time <- paste(as.Date(subsetDate$Date),subsetDate$Time)
subsetDate$Datetime <- as.POSIXct(date_time)
###########Converting Global_active_Power,Sub_metering_1,Sub_metering_2,Sub_metering_3 to numeric####
subsetDate$Global_active_power <- as.numeric(subsetDate$Global_active_power)
subsetDate$Sub_metering_1 <- as.numeric(subsetDate$Sub_metering_1)
subsetDate$Sub_metering_2 <- as.numeric(subsetDate$Sub_metering_2)
subsetDate$Sub_metering_3 <- as.numeric(subsetDate$Sub_metering_3)
########Exporting Data as Png File in given size of 480X480####
png("plot4.png", width=480, height=480)
#############Plotting  the Data##############
par(mfrow = c(2, 2))
plot(subsetDate$Datetime, subsetDate$Global_active_power, type="l", xlab="", ylab="Global Active Power", cex=0.2)
plot(subsetDate$Datetime,subsetDate$Voltage, type="l", xlab="datetime", ylab="Voltage")
plot(subsetDate$Datetime, subsetDate$Sub_metering_1, type="l", ylab="Energy Submetering", xlab="")
lines(subsetDate$Datetime, subsetDate$Sub_metering_2, type="l", col="red")
lines(subsetDate$Datetime, subsetDate$Sub_metering_3, type="l", col="blue")
legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty=, lwd=2.5, col=c("black", "red", "blue"), bty="o")
plot(subsetDate$Datetime, subsetDate$Global_reactive_power, type="l", xlab="datetime", ylab="Global_reactive_power")
dev.off()

Output:

For More Information Please Visit the UC Irvine Machine Learning Repository

You can also check my Github Page For reference Here

Note:

1 Comment

  1. info

    I enjoy reading a post that can make people think. Also, many thanks for allowing me
    to comment!
    my web-site … info

Leave a Reply

%d bloggers like this: