├── 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 /plot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caocscar/ExData_Plotting1/master/plot1.png -------------------------------------------------------------------------------- /plot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caocscar/ExData_Plotting1/master/plot2.png -------------------------------------------------------------------------------- /plot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caocscar/ExData_Plotting1/master/plot3.png -------------------------------------------------------------------------------- /plot4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caocscar/ExData_Plotting1/master/plot4.png -------------------------------------------------------------------------------- /figure/unnamed-chunk-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caocscar/ExData_Plotting1/master/figure/unnamed-chunk-2.png -------------------------------------------------------------------------------- /figure/unnamed-chunk-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caocscar/ExData_Plotting1/master/figure/unnamed-chunk-3.png -------------------------------------------------------------------------------- /figure/unnamed-chunk-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caocscar/ExData_Plotting1/master/figure/unnamed-chunk-4.png -------------------------------------------------------------------------------- /figure/unnamed-chunk-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caocscar/ExData_Plotting1/master/figure/unnamed-chunk-5.png -------------------------------------------------------------------------------- /plot1.R: -------------------------------------------------------------------------------- 1 | library(data.table) 2 | data <- fread("household_power_consumption.txt", na.strings="?") 3 | df <- with(data, data[(Date == "1/2/2007" | Date == "2/2/2007")]) 4 | df$datetime <- as.POSIXct(paste(df$Date, df$Time), format="%d/%m/%Y %H:%M:%S") 5 | # Plot 1 6 | hist(df$Global_active_power, col="red", main="Global Active Power", xlab="Global Active Power (kilowatts)") 7 | dev.copy(png, file = "plot1.png", width =480, height=480) 8 | dev.off() -------------------------------------------------------------------------------- /plot2.R: -------------------------------------------------------------------------------- 1 | library(data.table) 2 | data <- fread("household_power_consumption.txt", na.strings="?") 3 | df <- with(data, data[(Date == "1/2/2007" | Date == "2/2/2007")]) 4 | df$datetime <- as.POSIXct(paste(df$Date, df$Time), format="%d/%m/%Y %H:%M:%S") 5 | # Plot 2 6 | plot(df$datetime, df$Global_active_power, type="l", lwd=2, xlab="", ylab="Global Active Power (kilowatts)") 7 | dev.copy(png, file = "plot2.png", width =480, height=480) 8 | dev.off() -------------------------------------------------------------------------------- /plot3.R: -------------------------------------------------------------------------------- 1 | library(data.table) 2 | data <- fread("household_power_consumption.txt", na.strings="?") 3 | df <- with(data, data[(Date == "1/2/2007" | Date == "2/2/2007")]) 4 | df$datetime <- as.POSIXct(paste(df$Date, df$Time), format="%d/%m/%Y %H:%M:%S") 5 | # Plot 3 6 | plot(df$datetime,df$Sub_metering_1, type="n", xlab="", ylab="Energy sub metering") 7 | lines(df$datetime, df$Sub_metering_1, col="red") 8 | lines(df$datetime, df$Sub_metering_2, col="green") 9 | lines(df$datetime, df$Sub_metering_3, col="blue") 10 | legend("topright",legend=colnames(df)[7:9], 11 | lty=1, col=c("red","green","blue"), bty="n", inset=c(0.15,0), y.intersp=2) 12 | dev.copy(png, file = "plot3.png", width =480, height=480) 13 | dev.off() -------------------------------------------------------------------------------- /plot4.R: -------------------------------------------------------------------------------- 1 | library(data.table) 2 | data <- fread("household_power_consumption.txt", na.strings="?") 3 | df <- with(data, data[(Date == "1/2/2007" | Date == "2/2/2007")]) 4 | df$datetime <- as.POSIXct(paste(df$Date, df$Time), format="%d/%m/%Y %H:%M:%S") 5 | # Plot 4 6 | par(mfcol = c(2,2) ) 7 | par(mar = c(5,4,1,2)) 8 | plot(df$datetime, df$Global_active_power, type="l", lwd=2, xlab="", ylab="Global Active Power (kilowatts)") 9 | plot(df$datetime,df$Sub_metering_1, type="n", xlab="", ylab="Energy sub metering") 10 | lines(df$datetime, df$Sub_metering_1, col="red") 11 | lines(df$datetime, df$Sub_metering_2, col="green") 12 | lines(df$datetime, df$Sub_metering_3, col="blue") 13 | legend("topright",legend=colnames(df)[7:9], 14 | lty=1, col=c("red","green","blue"), bty="n", cex=0.9, inset=c(0.3,0), y.intersp=2) 15 | plot(df$datetime, df$Voltage, col="orange", type="l", lwd=2, xlab="datetime", ylab="Voltage") 16 | plot(df$datetime, df$Global_reactive_power, col="limegreen", type="l", lwd=2, xlab="datetime", ylab="Global Reactive Power") 17 | dev.copy(png, file = "plot4.png", width =480, height=480) 18 | 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 |