-
Notifications
You must be signed in to change notification settings - Fork 56.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73fe5c6
commit 7465103
Showing
8 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |