├── .gitignore ├── 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 ├── plot1.R ├── plot2.R ├── plot3.R ├── plot4.R └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | household_power_consumption.txt 2 | -------------------------------------------------------------------------------- /plot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mimoralea/ExData_Plotting1/master/plot1.png -------------------------------------------------------------------------------- /plot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mimoralea/ExData_Plotting1/master/plot2.png -------------------------------------------------------------------------------- /plot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mimoralea/ExData_Plotting1/master/plot3.png -------------------------------------------------------------------------------- /plot4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mimoralea/ExData_Plotting1/master/plot4.png -------------------------------------------------------------------------------- /figure/unnamed-chunk-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mimoralea/ExData_Plotting1/master/figure/unnamed-chunk-2.png -------------------------------------------------------------------------------- /figure/unnamed-chunk-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mimoralea/ExData_Plotting1/master/figure/unnamed-chunk-3.png -------------------------------------------------------------------------------- /figure/unnamed-chunk-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mimoralea/ExData_Plotting1/master/figure/unnamed-chunk-4.png -------------------------------------------------------------------------------- /figure/unnamed-chunk-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mimoralea/ExData_Plotting1/master/figure/unnamed-chunk-5.png -------------------------------------------------------------------------------- /plot1.R: -------------------------------------------------------------------------------- 1 | filename <- "household_power_consumption.txt" 2 | url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip" 3 | 4 | ## if data file is not found then pull it from 5 | ## the url given with the assignment 6 | ## clean up the zip file and only keep the 7 | ## inner text file 8 | if (!file.exists(filename)) { 9 | tmp_filename <- tempfile() 10 | if (download.file(url, 11 | tmp_filename, 12 | "curl") != 0) { 13 | stop("the file failed to download, will not proceed") 14 | } 15 | unzip(tmp_filename) 16 | unlink(tmp_filename) 17 | } 18 | 19 | ## load the specific data and clean values to be able to plot them 20 | pcons <- read.table(filename, skip = 66636, nrows = 2880, sep = ";") 21 | names(pcons) <- c("Date", "Time", "Global_active_power", "Global_reactive_power", "Voltage", 22 | "Global_intensity", "Sub_metering_1", "Sub_metering_2", "Sub_metering_3") 23 | 24 | ## get variables to plot 25 | gap <- pcons$Global_active_power 26 | 27 | ## actual plotting 28 | png("plot1.png", width=480, height=480) 29 | hist(gap, 30 | col="red", 31 | main="Global Active Power", 32 | xlab="Global Active Power (kilowatts)") 33 | dev.off() 34 | -------------------------------------------------------------------------------- /plot2.R: -------------------------------------------------------------------------------- 1 | filename <- "household_power_consumption.txt" 2 | url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip" 3 | 4 | ## if data file is not found then pull it from 5 | ## the url given with the assignment 6 | ## clean up the zip file and only keep the 7 | ## inner text file 8 | if (!file.exists(filename)) { 9 | tmp_filename <- tempfile() 10 | if (download.file(url, 11 | tmp_filename, 12 | "curl") != 0) { 13 | stop("the file failed to download, will not proceed") 14 | } 15 | unzip(tmp_filename) 16 | unlink(tmp_filename) 17 | } 18 | 19 | ## load the specific data and clean values to be able to plot them 20 | pcons <- read.table(filename, skip = 66636, nrows = 2880, sep = ";") 21 | names(pcons) <- c("Date", "Time", "Global_active_power", "Global_reactive_power", "Voltage", 22 | "Global_intensity", "Sub_metering_1", "Sub_metering_2", "Sub_metering_3") 23 | 24 | ## get variables to plot 25 | datetime <- strptime(paste(pcons$Date, pcons$Time, sep=" "), "%d/%m/%Y %H:%M:%S") 26 | 27 | ## do the actual plotting 28 | png("plot2.png", width=480, height=480) 29 | plot(datetime, gap, type="l", xlab="", ylab="Global Active Power (kilowatts)") 30 | dev.off() 31 | -------------------------------------------------------------------------------- /plot3.R: -------------------------------------------------------------------------------- 1 | filename <- "household_power_consumption.txt" 2 | url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip" 3 | 4 | ## if data file is not found then pull it from 5 | ## the url given with the assignment 6 | ## clean up the zip file and only keep the 7 | ## inner text file 8 | if (!file.exists(filename)) { 9 | tmp_filename <- tempfile() 10 | if (download.file(url, 11 | tmp_filename, 12 | "curl") != 0) { 13 | stop("the file failed to download, will not proceed") 14 | } 15 | unzip(tmp_filename) 16 | unlink(tmp_filename) 17 | } 18 | 19 | ## load the specific data and clean values to be able to plot them 20 | pcons <- read.table(filename, skip = 66636, nrows = 2880, sep = ";") 21 | names(pcons) <- c("Date", "Time", "Global_active_power", "Global_reactive_power", "Voltage", 22 | "Global_intensity", "Sub_metering_1", "Sub_metering_2", "Sub_metering_3") 23 | 24 | ## get variables to plot 25 | datetime <- strptime(paste(pcons$Date, pcons$Time, sep=" "), "%d/%m/%Y %H:%M:%S") 26 | sm1 <- pcons$Sub_metering_1 27 | sm2 <- pcons$Sub_metering_2 28 | sm3 <- pcons$Sub_metering_3 29 | 30 | ## do the actual plotting 31 | png("plot3.png", width=480, height=480) 32 | plot(datetime, sm1, type="n", ylab="Energy sub metering", xlab="") 33 | lines(datetime, sm1, type="l", col="black") 34 | lines(datetime, sm2, type="l", col="red") 35 | lines(datetime, sm3, type="l", col="blue") 36 | legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty=1, lwd=2.5, col=c("black", "red", "blue")) 37 | dev.off() 38 | -------------------------------------------------------------------------------- /plot4.R: -------------------------------------------------------------------------------- 1 | filename <- "household_power_consumption.txt" 2 | url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip" 3 | 4 | ## if data file is not found then pull it from 5 | ## the url given with the assignment 6 | ## clean up the zip file and only keep the 7 | ## inner text file 8 | if (!file.exists(filename)) { 9 | tmp_filename <- tempfile() 10 | if (download.file(url, 11 | tmp_filename, 12 | "curl") != 0) { 13 | stop("the file failed to download, will not proceed") 14 | } 15 | unzip(tmp_filename) 16 | unlink(tmp_filename) 17 | } 18 | 19 | ## load the specific data and clean values to be able to plot them 20 | pcons <- read.table(filename, skip = 66636, nrows = 2880, sep = ";") 21 | names(pcons) <- c("Date", "Time", "Global_active_power", "Global_reactive_power", "Voltage", 22 | "Global_intensity", "Sub_metering_1", "Sub_metering_2", "Sub_metering_3") 23 | 24 | ## get variables to plot 25 | datetime <- strptime(paste(pcons$Date, pcons$Time, sep=" "), "%d/%m/%Y %H:%M:%S") 26 | gap <- pcons$Global_active_power 27 | grp <- pcons$Global_reactive_power 28 | voltage <- pcons$Voltage 29 | sm1 <- pcons$Sub_metering_1 30 | sm2 <- pcons$Sub_metering_2 31 | sm3 <- pcons$Sub_metering_3 32 | 33 | ## do the actual plotting 34 | png("plot4.png", width=480, height=480) 35 | par(mfrow = c(2, 2)) 36 | plot(datetime, gap, type="l", xlab="", ylab="Global Active Power", cex=0.2) 37 | plot(datetime, voltage, type="l", xlab="datetime", ylab="Voltage") 38 | plot(datetime, sm1, type="l", ylab="Energy sub metering", xlab="") 39 | lines(datetime, sm2, type="l", col="red") 40 | lines(datetime, sm3, type="l", col="blue") 41 | legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty=, lwd=2.5, col=c("black", "red", "blue"), bty="n") 42 | plot(datetime, grp, type="l", xlab="datetime", ylab="Global_reactive_power") 43 | dev.off() 44 | -------------------------------------------------------------------------------- /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 |