├── plot1.png ├── plot2.png ├── plot3.png ├── plot4.png ├── figure ├── unnamed-chunk-2.png ├── unnamed-chunk-3.png ├── unnamed-chunk-4.png └── unnamed-chunk-5.png ├── plot2.R ├── plot1.R ├── plot3.R ├── plot4.R └── README.md /plot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/butchland/ExData_Plotting1/master/plot1.png -------------------------------------------------------------------------------- /plot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/butchland/ExData_Plotting1/master/plot2.png -------------------------------------------------------------------------------- /plot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/butchland/ExData_Plotting1/master/plot3.png -------------------------------------------------------------------------------- /plot4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/butchland/ExData_Plotting1/master/plot4.png -------------------------------------------------------------------------------- /figure/unnamed-chunk-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/butchland/ExData_Plotting1/master/figure/unnamed-chunk-2.png -------------------------------------------------------------------------------- /figure/unnamed-chunk-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/butchland/ExData_Plotting1/master/figure/unnamed-chunk-3.png -------------------------------------------------------------------------------- /figure/unnamed-chunk-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/butchland/ExData_Plotting1/master/figure/unnamed-chunk-4.png -------------------------------------------------------------------------------- /figure/unnamed-chunk-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/butchland/ExData_Plotting1/master/figure/unnamed-chunk-5.png -------------------------------------------------------------------------------- /plot2.R: -------------------------------------------------------------------------------- 1 | library(data.table) 2 | fileUrl <- "household_power_consumption.txt" 3 | colClasses <- c("character","character",rep("numeric",7)) 4 | dtFormat <- "%Y-%m-%d" 5 | DT <- read.table(fileUrl, header=TRUE,sep=";",na.strings="?",colClasses=colClasses) 6 | DT$Time <- strptime(paste(DT$Date,DT$Time,sep=" "),format="%d/%m/%Y %H:%M:%S") 7 | DT$Date <- as.Date(DT$Date,format="%d/%m/%Y") 8 | dtRange <- c(as.Date("2007-02-01",format=dtFormat),as.Date("2007-02-02",format=dtFormat)) 9 | subDT <- subset(DT, Date %in% dtRange) 10 | png(filename="plot2.png") 11 | with(subDT,plot(Time,Global_active_power, type="l", xlab="",ylab="Global Active Power (kilowatts)")) 12 | dev.off() 13 | -------------------------------------------------------------------------------- /plot1.R: -------------------------------------------------------------------------------- 1 | library(data.table) 2 | fileUrl <- "household_power_consumption.txt" 3 | colClasses <- c("character","character",rep("numeric",7)) 4 | dtFormat <- "%Y-%m-%d" 5 | DT <- read.table(fileUrl, header=TRUE,sep=";",na.strings="?",colClasses=colClasses) 6 | DT$Time <- strptime(paste(DT$Date,DT$Time,sep=" "),format="%d/%m/%Y %H:%M:%S") 7 | DT$Date <- as.Date(DT$Date,format="%d/%m/%Y") 8 | dtRange <- c(as.Date("2007-02-01",format=dtFormat),as.Date("2007-02-02",format=dtFormat)) 9 | subDT <- subset(DT, Date %in% dtRange) 10 | 11 | png(filename="plot1.png") 12 | hist(subDT$Global_active_power, col="RED",xlab="Global Active Power (kilowatts)",ylab="Frequency",main="Global Active Power") 13 | dev.off() 14 | 15 | 16 | -------------------------------------------------------------------------------- /plot3.R: -------------------------------------------------------------------------------- 1 | fileUrl <- "household_power_consumption.txt" 2 | colClasses <- c("character","character",rep("numeric",7)) 3 | dtFormat <- "%Y-%m-%d" 4 | dtRange <- c(as.Date("2007-02-01",format=dtFormat),as.Date("2007-02-02",format=dtFormat)) 5 | lineLabels <- c("Sub_metering_1","Sub_metering_2","Sub_metering_3") 6 | 7 | DT <- read.table(fileUrl, header=TRUE,sep=";",na.strings="?",colClasses=colClasses) 8 | DT$Time <- strptime(paste(DT$Date,DT$Time,sep=" "),format="%d/%m/%Y %H:%M:%S") 9 | DT$Date <- as.Date(DT$Date,format="%d/%m/%Y") 10 | subDT <- subset(DT, Date %in% dtRange) 11 | 12 | g <- gl(3,nrow(subDT),labels= lineLabels) 13 | x <- rep(subDT$Time,3) 14 | y <- c(subDT$Sub_metering_1,subDT$Sub_metering_2,subDT$Sub_metering_3) 15 | 16 | png(filename="plot3.png") 17 | plot(x,y, type="n", ylab="Energy sub metering",xlab="") 18 | points(x[g == "Sub_metering_1"],y[g == "Sub_metering_1"],col="BLACK",type="l") 19 | points(x[g == "Sub_metering_2"],y[g == "Sub_metering_2"],col="RED",type="l") 20 | points(x[g == "Sub_metering_3"],y[g == "Sub_metering_3"],col="BLUE",type="l") 21 | legend("topright",legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),col=c("BLACK","RED","BLUE"),lty=1) 22 | dev.off() 23 | -------------------------------------------------------------------------------- /plot4.R: -------------------------------------------------------------------------------- 1 | fileUrl <- "household_power_consumption.txt" 2 | colClasses <- c("character","character",rep("numeric",7)) 3 | dtFormat <- "%Y-%m-%d" 4 | dtRange <- c(as.Date("2007-02-01",format=dtFormat),as.Date("2007-02-02",format=dtFormat)) 5 | lineLabels <- c("Sub_metering_1","Sub_metering_2","Sub_metering_3") 6 | 7 | DT <- read.table(fileUrl, header=TRUE,sep=";",na.strings="?",colClasses=colClasses) 8 | DT$Time <- strptime(paste(DT$Date,DT$Time,sep=" "),format="%d/%m/%Y %H:%M:%S") 9 | DT$Date <- as.Date(DT$Date,format="%d/%m/%Y") 10 | subDT <- subset(DT, Date %in% dtRange) 11 | 12 | png(filename="plot4.png") 13 | par(mfrow=c(2,2)) 14 | # plot 4a 15 | with(subDT,plot(Time,Global_active_power, type="l", xlab="",ylab="Global Active Power")) 16 | # plot 4b 17 | with(subDT, plot(Time,Voltage, type="l",xlab="datetime")) 18 | 19 | 20 | # plot 4c 21 | g <- gl(3,nrow(subDT),labels= lineLabels) 22 | x <- rep(subDT$Time,3) 23 | y <- c(subDT$Sub_metering_1,subDT$Sub_metering_2,subDT$Sub_metering_3) 24 | plot(x,y, type="n", ylab="Energy sub metering",xlab="") 25 | points(x[g == "Sub_metering_1"],y[g == "Sub_metering_1"],col="BLACK",type="l") 26 | points(x[g == "Sub_metering_2"],y[g == "Sub_metering_2"],col="RED",type="l") 27 | points(x[g == "Sub_metering_3"],y[g == "Sub_metering_3"],col="BLUE",type="l") 28 | legend("topright",legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),col=c("BLACK","RED","BLUE"),lty=1,bty="n") 29 | 30 | # plot4d 31 | with(subDT, plot(Time,Global_reactive_power, type="l", xlab="datetime")) 32 | dev.off() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | 3 | This assignment uses data from 4 | the UC Irvine Machine 5 | Learning Repository, a popular repository for machine learning 6 | datasets. In particular, we will be using the "Individual household 7 | electric power consumption Data Set" which I have made available on 8 | the course web site: 9 | 10 | 11 | * Dataset: Electric power consumption [20Mb] 12 | 13 | * Description: Measurements of electric power consumption in 14 | one household with a one-minute sampling rate over a period of almost 15 | 4 years. Different electrical quantities and some sub-metering values 16 | are available. 17 | 18 | 19 | The following descriptions of the 9 variables in the dataset are taken 20 | from 21 | the UCI 22 | web site: 23 | 24 |