Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rdpeng/ExData_Plotting1
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: siggyworks/ExData_Plotting1
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 8 files changed
  • 1 contributor

Commits on Mar 5, 2015

  1. added R plotting scripts

    siggyworks committed Mar 5, 2015
    Copy the full SHA
    7465103 View commit details
Showing with 188 additions and 0 deletions.
  1. +39 −0 plot1.R
  2. BIN plot1.png
  3. +37 −0 plot2.R
  4. BIN plot2.png
  5. +43 −0 plot3.R
  6. BIN plot3.png
  7. +69 −0 plot4.R
  8. BIN plot4.png
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.