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.
implements R code to generate plots, adds plots to repo
- Loading branch information
Showing
8 changed files
with
142 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,20 @@ | ||
# read data | ||
data_ <- read.table("household_power_consumption.txt", sep = ";", na.strings = "?", header = T); | ||
# Convert date and time | ||
data_$Time <- strptime(x = paste(data_$Date, data_$Time, sep = " "), format = "%d/%m/%Y %H:%M:%S") | ||
data_$Date <- as.Date(data_$Date,format = '%d/%m/%Y') | ||
|
||
start_ <- as.Date("2007-02-01") | ||
end_ <- as.Date("2007-02-02") | ||
|
||
data2 <- data_[which(data_$Date >= start_ & data_$Date <= end_),] | ||
|
||
# draw plot 1 | ||
png(file = "plot1.png", width = 480, height = 480, units = "px") | ||
|
||
hist(data2$Global_active_power, | ||
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,23 @@ | ||
# read data | ||
data_ <- read.table("household_power_consumption.txt", sep = ";", na.strings = "?", header = T); | ||
# Convert date and time | ||
data_$Time <- strptime(x = paste(data_$Date, data_$Time, sep = " "), format = "%d/%m/%Y %H:%M:%S") | ||
data_$Date <- as.Date(data_$Date,format = '%d/%m/%Y') | ||
|
||
start_ <- as.Date("2007-02-01") | ||
end_ <- as.Date("2007-02-02") | ||
|
||
data2 <- data_[which(data_$Date >= start_ & data_$Date <= end_),] | ||
|
||
# draw plot 2 | ||
png(file = "plot2.png", width = 480, height = 480, units = "px") | ||
|
||
plot( | ||
x = data2$Time, | ||
y = data2$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,35 @@ | ||
# read data | ||
data_ <- read.table("household_power_consumption.txt", sep = ";", na.strings = "?", header = T); | ||
# Convert date and time | ||
data_$Time <- strptime(x = paste(data_$Date, data_$Time, sep = " "), format = "%d/%m/%Y %H:%M:%S") | ||
data_$Date <- as.Date(data_$Date,format = '%d/%m/%Y') | ||
|
||
start_ <- as.Date("2007-02-01") | ||
end_ <- as.Date("2007-02-02") | ||
|
||
data2 <- data_[which(data_$Date >= start_ & data_$Date <= end_),] | ||
|
||
# draw plot 3 | ||
png(file = "plot3.png", width = 480, height = 480, units = "px") | ||
|
||
plot( | ||
x = data2$Time, | ||
y = data2$Sub_metering_1, | ||
type = "l", | ||
xlab="", | ||
ylab="Energy sub metering" | ||
) | ||
|
||
lines( | ||
x=data2$Time, | ||
y=data2$Sub_metering_2, | ||
col="red") | ||
|
||
lines( | ||
x=data2$Time, | ||
y=data2$Sub_metering_3, | ||
col="blue") | ||
|
||
legend("topright",c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),bty="l",col=c("black","red","blue"),lwd=2,cex=0.7) | ||
|
||
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,64 @@ | ||
# read data | ||
data_ <- read.table("household_power_consumption.txt", sep = ";", na.strings = "?", header = T); | ||
# Convert date and time | ||
data_$Time <- strptime(x = paste(data_$Date, data_$Time, sep = " "), format = "%d/%m/%Y %H:%M:%S") | ||
data_$Date <- as.Date(data_$Date,format = '%d/%m/%Y') | ||
|
||
start_ <- as.Date("2007-02-01") | ||
end_ <- as.Date("2007-02-02") | ||
|
||
data2 <- data_[which(data_$Date >= start_ & data_$Date <= end_),] | ||
|
||
# draw plot 4 | ||
png(file = "plot4.png", width = 480, height = 480, units = "px") | ||
|
||
par(mfrow=c(2,2)) | ||
# 1 | ||
plot( | ||
x = data2$Time, | ||
y = data2$Global_active_power, | ||
type = "l", | ||
xlab="", | ||
ylab="Global Active Power" | ||
) | ||
|
||
# 2 | ||
plot( | ||
x = data2$Time, | ||
y = data2$Voltage, | ||
type = "l", | ||
xlab="datetime", | ||
ylab="Voltage" | ||
) | ||
|
||
# 3 | ||
plot( | ||
x = data2$Time, | ||
y = data2$Sub_metering_1, | ||
type = "l", | ||
xlab="", | ||
ylab="Energy sub metering" | ||
) | ||
|
||
lines( | ||
x=data2$Time, | ||
y=data2$Sub_metering_2, | ||
col="red") | ||
|
||
lines( | ||
x=data2$Time, | ||
y=data2$Sub_metering_3, | ||
col="blue") | ||
|
||
legend("topright",c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),bty="l",col=c("black","red","blue"),lwd=2,cex=0.7) | ||
|
||
# 4 | ||
plot( | ||
x = data2$Time, | ||
y = data2$Global_reactive_power, | ||
type = "l", | ||
xlab="datetime", | ||
ylab="Global_reactive_power" | ||
) | ||
|
||
dev.off() |