Skip to content

Commit 2b19493

Browse files
committed
Assignment 1
Assignment 1 complete
1 parent 73fe5c6 commit 2b19493

8 files changed

Lines changed: 69 additions & 0 deletions

File tree

plot1.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# plot1.R to plot global active power
2+
3+
## Read and subset data for proper dates
4+
data <- read.table('household_power_consumption.txt',na.strings="?",header=T,sep=";",colClasses=c('character','character','numeric',
5+
'numeric', 'numeric', 'numeric','numeric', 'numeric', 'numeric'))
6+
data$DateTime <- strptime(paste(data$Date, data$Time),"%d/%m/%Y %H:%M:%S")
7+
plotData <- subset(data,as.Date(DateTime) <= as.Date("2007-02-02") & as.Date(DateTime) >= as.Date("2007-02-01"))
8+
9+
## Build plot and save png
10+
png("plot1.png",height=504,width=504,bg="transparent")
11+
hist(plotData$Global_active_power,col="Red",xlab="Global Active Power (kilowatts)",main="Global Active Power")
12+
dev.off()

plot1.png

15.9 KB
Loading

plot2.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# plot2.R to plot global active power time series
2+
3+
## Read and subset data for proper dates
4+
data <- read.table('household_power_consumption.txt',na.strings="?",header=T,sep=";",colClasses=c('character','character','numeric',
5+
'numeric', 'numeric', 'numeric','numeric', 'numeric', 'numeric'))
6+
data$DateTime <- strptime(paste(data$Date, data$Time),"%d/%m/%Y %H:%M:%S")
7+
plotData <- subset(data,as.Date(DateTime) <= as.Date("2007-02-02") & as.Date(DateTime) >= as.Date("2007-02-01"))
8+
9+
## Build plot and save png
10+
png("plot2.png",height=504,width=504,bg="transparent")
11+
plot(plotData$DateTime,plotData$Global_active_power,pch=NA,ylab="Global Active Power (kilowatts)",xlab="")
12+
lines(plotData$DateTime,plotData$Global_active_power)
13+
dev.off()

plot2.png

29.7 KB
Loading

plot3.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# plot3.R to plot global active power time series energy submetering
2+
3+
## Read and subset data for proper dates
4+
data <- read.table('household_power_consumption.txt',na.strings="?",header=T,sep=";",colClasses=c('character','character','numeric',
5+
'numeric', 'numeric', 'numeric','numeric', 'numeric', 'numeric'))
6+
data$DateTime <- strptime(paste(data$Date, data$Time),"%d/%m/%Y %H:%M:%S")
7+
plotData <- subset(data,as.Date(DateTime) <= as.Date("2007-02-02") & as.Date(DateTime) >= as.Date("2007-02-01"))
8+
9+
## Build plot and save png
10+
png("plot3.png",height=504,width=504,bg="transparent")
11+
plot(plotData$DateTime,plotData$Sub_metering_1,pch=NA,ylab="Energy sub metering",xlab="")
12+
lines(plotData$DateTime,plotData$Sub_metering_1,col="Black")
13+
lines(plotData$DateTime,plotData$Sub_metering_2,col="Red")
14+
lines(plotData$DateTime,plotData$Sub_metering_3,col="Blue")
15+
legend("topright",c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),col=c("Black", "Red", "blue"),lty=c(1,1,1))
16+
dev.off()

plot3.png

27.1 KB
Loading

plot4.R

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# plot4.R to plot global active power multiplot
2+
3+
## Read and subset data for proper dates
4+
data <- read.table('household_power_consumption.txt',na.strings="?",header=T,sep=";",colClasses=c('character','character','numeric',
5+
'numeric', 'numeric', 'numeric','numeric', 'numeric', 'numeric'))
6+
data$DateTime <- strptime(paste(data$Date, data$Time),"%d/%m/%Y %H:%M:%S")
7+
plotData <- subset(data,as.Date(DateTime) <= as.Date("2007-02-02") & as.Date(DateTime) >= as.Date("2007-02-01"))
8+
9+
## Build plot and save png
10+
png("plot4.png",height=504,width=504,bg="transparent")
11+
par(mfrow=c(2,2))
12+
13+
plot(plotData$DateTime,plotData$Global_active_power,pch=NA,ylab="Global Active Power",xlab="")
14+
lines(plotData$DateTime,plotData$Global_active_power)
15+
16+
plot(plotData$DateTime,plotData$Voltage,xlab="datetime",ylab="Voltage",pch=NA)
17+
lines(plotData$DateTime, plotData$Voltage)
18+
19+
plot(plotData$DateTime,plotData$Sub_metering_1,pch=NA,ylab="Energy sub metering",xlab="")
20+
lines(plotData$DateTime,plotData$Sub_metering_1,col="Black")
21+
lines(plotData$DateTime,plotData$Sub_metering_2,col="Red")
22+
lines(plotData$DateTime,plotData$Sub_metering_3,col="Blue")
23+
legend("topright",c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),col=c("Black", "Red", "blue"),lty=c(1,1,1))
24+
25+
with(plotData,plot(DateTime,Global_reactive_power,pch=NA,xlab="datetime"))
26+
with(plotData,lines(DateTime,Global_reactive_power))
27+
28+
dev.off()

plot4.png

53.6 KB
Loading

0 commit comments

Comments
 (0)