Skip to content

Commit 2265bc9

Browse files
committed
Added R code and saved plots
1 parent 73fe5c6 commit 2265bc9

File tree

9 files changed

+562
-0
lines changed

9 files changed

+562
-0
lines changed

.Rhistory

Lines changed: 512 additions & 0 deletions
Large diffs are not rendered by default.

plot1.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#setwd("C:/Users/hariz_000/Dropbox/R/exdata-002/")
2+
data <- read.table("household_power_consumption.txt",header = T, sep = ";",as.is=T,na.strings = "?")
3+
data$Date <- as.Date(data$Date,"%d/%m/%Y")
4+
data <- data[data$Date == '2007-02-01' | data$Date == '2007-02-02',]
5+
for(i in 3:9) data[,i] <- as.numeric(data[,i])
6+
png("plot1.png")
7+
with(data,hist(Global_active_power,main = "Global Active Power",col='red',xlab = 'Global Active Power (kilowatts)'))
8+
dev.off()

plot1.png

12.2 KB
Loading

plot2.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#setwd("C:/Users/hariz_000/Dropbox/R/exdata-002/")
2+
data <- read.table("household_power_consumption.txt",header = T, sep = ";",as.is=T,na.strings = "?")
3+
data$Date <- as.Date(data$Date,"%d/%m/%Y")
4+
data <- data[data$Date == '2007-02-01' | data$Date == '2007-02-02',]
5+
for(i in 3:9) data[,i] <- as.numeric(data[,i])
6+
7+
8+
png("plot2.png")
9+
with(data,plot(strptime(paste(Date,Time),"%Y-%m-%d %H:%M:%S"),Global_active_power,type='l',xlab="",ylab = 'Global Active Power (kilowatts)'))
10+
dev.off()

plot2.png

16 KB
Loading

plot3.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#setwd("C:/Users/hariz_000/Dropbox/R/exdata-002/")
2+
data <- read.table("household_power_consumption.txt",header = T, sep = ";",as.is=T,na.strings = "?")
3+
data$Date <- as.Date(data$Date,"%d/%m/%Y")
4+
data <- data[data$Date == '2007-02-01' | data$Date == '2007-02-02',]
5+
for(i in 3:9) data[,i] <- as.numeric(data[,i])
6+
7+
png("plot3.png")
8+
with(data,plot(strptime(paste(Date,Time),"%Y-%m-%d %H:%M:%S"),Sub_metering_1,type='l',xlab="",ylab = 'Energy sub metering'))
9+
with(data,lines(strptime(paste(Date,Time),"%Y-%m-%d %H:%M:%S"),Sub_metering_2,col='red'))
10+
with(data,lines(strptime(paste(Date,Time),"%Y-%m-%d %H:%M:%S"),Sub_metering_3,col='blue'))
11+
legend("topright",legend = c('Sub_metering_1','Sub_metering_2','Sub_metering_3'),col=c('black','red','blue'),lwd=1)
12+
dev.off()

plot3.png

15.2 KB
Loading

plot4.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#setwd("C:/Users/hariz_000/Dropbox/R/exdata-002/")
2+
data <- read.table("household_power_consumption.txt",header = T, sep = ";",as.is=T,na.strings = "?")
3+
data$Date <- as.Date(data$Date,"%d/%m/%Y")
4+
data <- data[data$Date == '2007-02-01' | data$Date == '2007-02-02',]
5+
for(i in 3:9) data[,i] <- as.numeric(data[,i])
6+
7+
png("plot4.png")
8+
par(mfrow=c(2,2))
9+
with(data,plot(strptime(paste(Date,Time),"%Y-%m-%d %H:%M:%S"),
10+
Global_active_power,type='l',xlab="",
11+
ylab = 'Global Active Power (kilowatts)'))
12+
with(data,plot(strptime(paste(Date,Time),"%Y-%m-%d %H:%M:%S"),Voltage,
13+
type='l',xlab='datetime',ylab='Voltage'))
14+
with(data,plot(strptime(paste(Date,Time),"%Y-%m-%d %H:%M:%S"),Sub_metering_1,type='l',xlab="",ylab = 'Energy sub metering'))
15+
with(data,lines(strptime(paste(Date,Time),"%Y-%m-%d %H:%M:%S"),Sub_metering_2,col='red'))
16+
with(data,lines(strptime(paste(Date,Time),"%Y-%m-%d %H:%M:%S"),Sub_metering_3,col='blue'))
17+
legend("topright",legend = c('Sub_metering_1','Sub_metering_2','Sub_metering_3'),col=c('black','red','blue'),lwd=1)
18+
with(data,plot(strptime(paste(Date,Time),"%Y-%m-%d %H:%M:%S"),
19+
Global_reactive_power,type='l',xlab='datetime'))
20+
dev.off()

plot4.png

45.3 KB
Loading

0 commit comments

Comments
 (0)