forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added plot1.R, plot1.png, plot2.R and plot2.png
- Loading branch information
jsubirat
committed
Feb 8, 2015
1 parent
73fe5c6
commit e287353
Showing
4 changed files
with
57 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,28 @@ | ||
# Data downloading and reading | ||
fileURL<-"https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip" | ||
download.file(fileURL, destfile="./exdata-data-household_power_consumption.zip", method="curl") | ||
unzip("exdata-data-household_power_consumption.zip") | ||
conn <- file("household_power_consumption.txt", "r") | ||
|
||
data <- read.table(conn, | ||
sep = ";", | ||
comment.char = "", | ||
na.strings = "?", | ||
header = TRUE, | ||
colClasses = c("character", "character", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric")) | ||
|
||
#Convert Date and Time into one single DateAndTime variable | ||
data$DateAndTime <- as.POSIXct(paste(data$Date, data$Time), format="%d/%m/%Y %H:%M:%S") | ||
data$Time <- NULL | ||
data$Date <- NULL | ||
|
||
#Subset the dataset to the following date range: 2007-02-01 and 2007-02-02 | ||
libary(dplyr) | ||
dateFrom <- as.POSIXct("01/02/2007 00:00:00", format="%d/%m/%Y %H:%M:%S") | ||
dateUntil <- as.POSIXct("03/02/2007 00:00:00", format="%d/%m/%Y %H:%M:%S") | ||
data <- filter(data, DateAndTime >= dateFrom & DateAndTime < dateUntil) | ||
|
||
# Plot it into a png file | ||
png(file = "plot1.png", width = 480, height = 480) | ||
hist(data$Global_active_power, col = "red", main = "Global Active Power", xlab = "Global Active Power (kilowatts)") | ||
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,29 @@ | ||
# Data downloading and reading | ||
fileURL<-"https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip" | ||
download.file(fileURL, destfile="./exdata-data-household_power_consumption.zip", method="curl") | ||
unzip("exdata-data-household_power_consumption.zip") | ||
conn <- file("household_power_consumption.txt", "r") | ||
|
||
data <- read.table(conn, | ||
sep = ";", | ||
comment.char = "", | ||
na.strings = "?", | ||
header = TRUE, | ||
colClasses = c("character", "character", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric")) | ||
|
||
#Convert Date and Time into one single DateAndTime variable | ||
data$DateAndTime <- as.POSIXct(paste(data$Date, data$Time), format="%d/%m/%Y %H:%M:%S") | ||
data$Time <- NULL | ||
data$Date <- NULL | ||
|
||
#Subset the dataset to the following date range: 2007-02-01 and 2007-02-02 | ||
libary(dplyr) | ||
dateFrom <- as.POSIXct("01/02/2007 00:00:00", format="%d/%m/%Y %H:%M:%S") | ||
dateUntil <- as.POSIXct("03/02/2007 00:00:00", format="%d/%m/%Y %H:%M:%S") | ||
data <- filter(data, DateAndTime >= dateFrom & DateAndTime < dateUntil) | ||
|
||
# Plot it into a png file | ||
png(file = "plot2.png", width = 480, height = 480) | ||
with(data, plot(DateAndTime, Global_active_power, type = "l", xlab = "", ylab = "Global Active Power (kilowatts)")) | ||
dev.off() | ||
|