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.
- Loading branch information
1 parent
73fe5c6
commit b8d70a9
Showing
10 changed files
with
131 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,4 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata |
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,13 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: Sweave | ||
LaTeX: pdfLaTeX |
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,24 @@ | ||
#load data.table library | ||
library("data.table") | ||
|
||
# Read file | ||
householdEPC <- data.table::fread(input = "../data/household_power_consumption.txt", na.strings="?") | ||
|
||
# Convert values to numeric | ||
householdEPC[, Global_active_power := lapply(.SD, as.numeric), .SDcols = c("Global_active_power")] | ||
|
||
# Parse date | ||
householdEPC[, Date := lapply(.SD, as.Date, "%d/%m/%Y"), .SDcols = c("Date")] | ||
|
||
# Subset observations from 2007-02-01 to 2007-02-02 | ||
householdEPC <- householdEPC[(Date >= "2007-02-01") & (Date <= "2007-02-02")] | ||
|
||
#Open de graphic device of type PNG | ||
png("plot1.png", width=480, height=480) | ||
|
||
## Plot 1 | ||
hist(householdEPC[, Global_active_power], main="Global Active Power", | ||
xlab="Global Active Power (kilowatts)", ylab="Frequency", col="Red") | ||
|
||
# Close the device to save the file | ||
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,23 @@ | ||
#load data.table library | ||
library("data.table") | ||
|
||
# Read file | ||
householdEPC <- data.table::fread(input = "../data/household_power_consumption.txt", na.strings="?") | ||
|
||
# Convert values to numeric | ||
householdEPC[, Global_active_power := lapply(.SD, as.numeric), .SDcols = c("Global_active_power")] | ||
|
||
#Convert to POSIXct to use week days | ||
householdEPC[, dateTime := as.POSIXct(paste(Date, Time), format = "%d/%m/%Y %H:%M:%S")] | ||
|
||
# Subset observations from 2007-02-01 to 2007-02-02 | ||
householdEPC <- householdEPC[(dateTime >= "2007-02-01") & (dateTime < "2007-02-03")] | ||
|
||
png("plot2.png", width=480, height=480) | ||
|
||
## Plot 2 | ||
plot(x = householdEPC[, dateTime] | ||
, y = householdEPC[, Global_active_power] | ||
, type="l", xlab="", ylab="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,27 @@ | ||
#load data.table library | ||
library("data.table") | ||
|
||
# Read file | ||
householdEPC <- data.table::fread(input = "../data/household_power_consumption.txt", na.strings="?") | ||
|
||
# Convert values to numeric | ||
householdEPC[, Global_active_power := lapply(.SD, as.numeric), .SDcols = c("Global_active_power")] | ||
|
||
#Convert to POSIXct to use week days | ||
householdEPC[, dateTime := as.POSIXct(paste(Date, Time), format = "%d/%m/%Y %H:%M:%S")] | ||
|
||
# Subset observations from 2007-02-01 to 2007-02-02 | ||
householdEPC <- householdEPC[(dateTime >= "2007-02-01") & (dateTime < "2007-02-03")] | ||
|
||
png("plot3.png", width=480, height=480) | ||
|
||
# Plot 3 | ||
plot(householdEPC[, dateTime], householdEPC[, Sub_metering_1], type="l", xlab="", ylab="Energy sub metering") | ||
lines(householdEPC[, dateTime], householdEPC[, Sub_metering_2],col="red") | ||
lines(householdEPC[, dateTime], householdEPC[, Sub_metering_3],col="blue") | ||
legend("topright" | ||
, col=c("black","red","blue") | ||
, c("Sub_metering_1 ","Sub_metering_2 ", "Sub_metering_3 ") | ||
,lty=c(1,1), lwd=c(1,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,40 @@ | ||
#load data.table library | ||
#load data.table library | ||
library("data.table") | ||
|
||
# Read file | ||
householdEPC <- data.table::fread(input = "../data/household_power_consumption.txt", na.strings="?") | ||
|
||
# Convert values to numeric | ||
householdEPC[, Global_active_power := lapply(.SD, as.numeric), .SDcols = c("Global_active_power")] | ||
|
||
#Convert to POSIXct to use week days | ||
householdEPC[, dateTime := as.POSIXct(paste(Date, Time), format = "%d/%m/%Y %H:%M:%S")] | ||
|
||
# Subset observations from 2007-02-01 to 2007-02-02 | ||
householdEPC <- householdEPC[(dateTime >= "2007-02-01") & (dateTime < "2007-02-03")] | ||
|
||
png("plot4.png", width=480, height=480) | ||
|
||
par(mfrow=c(2,2)) | ||
|
||
# Plot 1 | ||
plot(householdEPC[, dateTime], householdEPC[, Global_active_power], type="l", xlab="", ylab="Global Active Power") | ||
|
||
# Plot 2 | ||
plot(householdEPC[, dateTime],householdEPC[, Voltage], type="l", xlab="datetime", ylab="Voltage") | ||
|
||
# Plot 3 | ||
plot(householdEPC[, dateTime], householdEPC[, Sub_metering_1], type="l", xlab="", ylab="Energy sub metering") | ||
lines(householdEPC[, dateTime], householdEPC[, Sub_metering_2], col="red") | ||
lines(householdEPC[, dateTime], householdEPC[, Sub_metering_3],col="blue") | ||
legend("topright", col=c("black","red","blue") | ||
, c("Sub_metering_1 ","Sub_metering_2 ", "Sub_metering_3 ") | ||
, lty=c(1,1) | ||
, bty="n" | ||
, cex=.5) | ||
|
||
# Plot 4 | ||
plot(householdEPC[, dateTime], householdEPC[,Global_reactive_power], type="l", xlab="datetime", ylab="Global_reactive_power") | ||
|
||
dev.off() |