diff --git a/plot1.R b/plot1.R new file mode 100644 index 00000000000..c81ff07ab3c --- /dev/null +++ b/plot1.R @@ -0,0 +1,39 @@ +## Project 1 Assignment: Exploratory Data Analysis (plot1.R) + +## This script reads in the sample datat provided in file ./household_power_consumption.txt + +## Read the data +poweruse <- read.table("household_power_consumption.txt", + header=TRUE, sep=";", + skip=66636, nrows=2880, + stringsAsFactors=FALSE, + na.strings="?", + quote="") + +## Label the columns +names(poweruse) <- c("Date", + "Time", + "Global_active_power", + "Global_reactive_power", + "Voltage", + "Global_intensity", + "Sub_metering_1", + "Sub_metering_2", + "Sub_metering_3") + +## Merge "Date" and "Time" columns and add as another column +poweruse$DateTime <- do.call(paste,poweruse[c("Date","Time")]) + +## Convert the DateTime column to the right datatype +poweruse$DateTime <- strptime(poweruse$DateTime,"%d/%m/%Y %H:%M:%S") + +## Create the plot: Histogram of Global Active Power +png(file="plot1.png", width=480, height=480, bg="transparent") +hist(poweruse$Global_active_power, + breaks=6, + main="Global Active Power", + xlab = "Global Active Power (kilowatts)", + col="red") +dev.off() + + diff --git a/plot1.png b/plot1.png new file mode 100644 index 00000000000..1f6cff8fd6d Binary files /dev/null and b/plot1.png differ diff --git a/plot2.R b/plot2.R new file mode 100644 index 00000000000..4d729673c81 --- /dev/null +++ b/plot2.R @@ -0,0 +1,37 @@ +## Project 1 Assignment: Exploratory Data Analysis (plot2.R) + +## This script reads in the sample datat provided in file ./household_power_consumption.txt + +## Read the data +poweruse <- read.table("household_power_consumption.txt", + header=TRUE, sep=";", + skip=66636, nrows=2880, + stringsAsFactors=FALSE, + na.strings="?", + quote="") + +## Label the columns +names(poweruse) <- c("Date", + "Time", + "Global_active_power", + "Global_reactive_power", + "Voltage", + "Global_intensity", + "Sub_metering_1", + "Sub_metering_2", + "Sub_metering_3") + +## Merge "Date" and "Time" columns and add as another column +poweruse$DateTime <- do.call(paste,poweruse[c("Date","Time")]) + +## Convert the DateTime column to the right datatype +poweruse$DateTime <- strptime(poweruse$DateTime,"%d/%m/%Y %H:%M:%S") + +## Create the plot: Line graph of Global Active Power +png(file="plot2.png", width=480, height=480, bg="transparent") +plot(poweruse$DateTime, + poweruse$Global_active_power, + ylab = "Global Active Power (kilowatts)", + type="l", + xlab=NA) +dev.off() diff --git a/plot2.png b/plot2.png new file mode 100644 index 00000000000..cc92b845207 Binary files /dev/null and b/plot2.png differ diff --git a/plot3.R b/plot3.R new file mode 100644 index 00000000000..4a7a7342403 --- /dev/null +++ b/plot3.R @@ -0,0 +1,43 @@ +## Project 1 Assignment: Exploratory Data Analysis (plot3.R) + +## This script reads in the sample datat provided in file ./household_power_consumption.txt + +## Read the data +poweruse <- read.table("household_power_consumption.txt", + header=TRUE, sep=";", + skip=66636, nrows=2880, + stringsAsFactors=FALSE, + na.strings="?", + quote="") + +## Label the columns +names(poweruse) <- c("Date", + "Time", + "Global_active_power", + "Global_reactive_power", + "Voltage", + "Global_intensity", + "Sub_metering_1", + "Sub_metering_2", + "Sub_metering_3") + +## Merge "Date" and "Time" columns and add as another column +poweruse$DateTime <- do.call(paste,poweruse[c("Date","Time")]) + +## Convert the DateTime column to the right datatype +poweruse$DateTime <- strptime(poweruse$DateTime,"%d/%m/%Y %H:%M:%S") + +## Create the plot: Line graph of Submetering 1, 2 and 3 +png(file="plot3.png", width=480, height=480, bg="transparent") +plot(poweruse$DateTime, + poweruse$Sub_metering_1, + ylab = "Energy sub metering", + type="l", + xlab=NA) +lines(poweruse$DateTime,poweruse$Sub_metering_2, col="blue",type="l") +lines(poweruse$DateTime,poweruse$Sub_metering_3, col="red",type="l") +legend("topright", + legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"), + col=c("black","blue","red"), + lty=1) +dev.off() diff --git a/plot3.png b/plot3.png new file mode 100644 index 00000000000..0f699ed93e7 Binary files /dev/null and b/plot3.png differ diff --git a/plot4.R b/plot4.R new file mode 100644 index 00000000000..95a75289876 --- /dev/null +++ b/plot4.R @@ -0,0 +1,69 @@ +## Project 1 Assignment: Exploratory Data Analysis (plot4.R) + +## This script reads in the sample data provided in file ./household_power_consumption.txt + +## Read the data +poweruse <- read.table("household_power_consumption.txt", + header=TRUE, sep=";", + skip=66636, nrows=2880, + stringsAsFactors=FALSE, + na.strings="?", + quote="") + +## Label the columns +names(poweruse) <- c("Date", + "Time", + "Global_active_power", + "Global_reactive_power", + "Voltage", + "Global_intensity", + "Sub_metering_1", + "Sub_metering_2", + "Sub_metering_3") + +## Merge "Date" and "Time" columns and add as another column +poweruse$DateTime <- do.call(paste,poweruse[c("Date","Time")]) + +## Convert the DateTime column to the right datatype +poweruse$DateTime <- strptime(poweruse$DateTime,"%d/%m/%Y %H:%M:%S") + +## Create the plot: 4 x 4 grid of plots +png(file="plot4.png", width=480, height=480, bg="transparent") +par(mfrow=c(2,2)) ## set the grid + +#plot 1 +plot(poweruse$DateTime, + poweruse$Global_active_power, + ylab = "Global Active Power (kilowatts)", + type="l", + xlab=NA) + +#plot 2 +plot(poweruse$DateTime, + poweruse$Voltage, + ylab = "Voltage", + type="l", + xlab="datetime") + +#plot 3 +plot(poweruse$DateTime, + poweruse$Sub_metering_1, + ylab = "Energy sub metering", + type="l", + xlab=NA) +lines(poweruse$DateTime,poweruse$Sub_metering_2, col="blue",type="l") +lines(poweruse$DateTime,poweruse$Sub_metering_3, col="red",type="l") +legend("topright", + legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"), + col=c("black","blue","red"), + bty="n", + lty=1) + +#plot 4 +plot(poweruse$DateTime, + poweruse$Global_reactive_power, + ylab = "Global_reactive_power", + type="l", + xlab="datetime") + +dev.off() diff --git a/plot4.png b/plot4.png new file mode 100644 index 00000000000..88d1bf316db Binary files /dev/null and b/plot4.png differ