Skip to content

Commit

Permalink
added R plotting scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
siggyworks committed Mar 5, 2015
1 parent 73fe5c6 commit 7465103
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 0 deletions.
39 changes: 39 additions & 0 deletions plot1.R
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()


Binary file added plot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions plot2.R
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()
Binary file added plot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions plot3.R
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()
Binary file added plot3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions plot4.R
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()
Binary file added plot4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7465103

Please sign in to comment.