diff --git a/plot1.R b/plot1.R new file mode 100644 index 00000000000..e59af2f296c --- /dev/null +++ b/plot1.R @@ -0,0 +1,9 @@ +dataFile <- "./data/household_power_consumption.txt" +data <- read.table(dataFile, header=TRUE, sep=";", stringsAsFactors=FALSE, dec=".") +subSetData <- data[data$Date %in% c("1/2/2007","2/2/2007") ,] + +#str(subSetData) +globalActivePower <- as.numeric(subSetData$Global_active_power) +png("plot1.png", width=480, height=480) +hist(globalActivePower, col="red", main="Global Active Power", xlab="Global Active Power (kilowatts)") +dev.off() \ No newline at end of file diff --git a/plot1.png b/plot1.png new file mode 100644 index 00000000000..f1e0eed5e6c Binary files /dev/null and b/plot1.png differ diff --git a/plot2.R b/plot2.R new file mode 100644 index 00000000000..28314d7a553 --- /dev/null +++ b/plot2.R @@ -0,0 +1,10 @@ +dataFile <- "./data/household_power_consumption.txt" +data <- read.table(dataFile, header=TRUE, sep=";", stringsAsFactors=FALSE, dec=".") +subSetData <- data[data$Date %in% c("1/2/2007","2/2/2007") ,] + +#str(subSetData) +datetime <- strptime(paste(subSetData$Date, subSetData$Time, sep=" "), "%d/%m/%Y %H:%M:%S") +globalActivePower <- as.numeric(subSetData$Global_active_power) +png("plot2.png", width=480, height=480) +plot(datetime, globalActivePower, type="l", xlab="", ylab="Global Active Power (kilowatts)") +dev.off() \ No newline at end of file diff --git a/plot2.png b/plot2.png new file mode 100644 index 00000000000..42f7dc85fb6 Binary files /dev/null and b/plot2.png differ diff --git a/plot3.R b/plot3.R new file mode 100644 index 00000000000..4799b8d3ba7 --- /dev/null +++ b/plot3.R @@ -0,0 +1,17 @@ +dataFile <- "./data/household_power_consumption.txt" +data <- read.table(dataFile, header=TRUE, sep=";", stringsAsFactors=FALSE, dec=".") +subSetData <- data[data$Date %in% c("1/2/2007","2/2/2007") ,] + +#str(subSetData) +datetime <- strptime(paste(subSetData$Date, subSetData$Time, sep=" "), "%d/%m/%Y %H:%M:%S") +globalActivePower <- as.numeric(subSetData$Global_active_power) +subMetering1 <- as.numeric(subSetData$Sub_metering_1) +subMetering2 <- as.numeric(subSetData$Sub_metering_2) +subMetering3 <- as.numeric(subSetData$Sub_metering_3) + +png("plot3.png", width=480, height=480) +plot(datetime, subMetering1, type="l", ylab="Energy Submetering", xlab="") +lines(datetime, subMetering2, type="l", col="red") +lines(datetime, subMetering3, type="l", col="blue") +legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty=1, lwd=2.5, col=c("black", "red", "blue")) +dev.off() \ No newline at end of file diff --git a/plot3.png b/plot3.png new file mode 100644 index 00000000000..0c570c7d1b1 Binary files /dev/null and b/plot3.png differ diff --git a/plot4.R b/plot4.R new file mode 100644 index 00000000000..23d623793a9 --- /dev/null +++ b/plot4.R @@ -0,0 +1,29 @@ +dataFile <- "./data/household_power_consumption.txt" +data <- read.table(dataFile, header=TRUE, sep=";", stringsAsFactors=FALSE, dec=".") +subSetData <- data[data$Date %in% c("1/2/2007","2/2/2007") ,] + +#str(subSetData) +datetime <- strptime(paste(subSetData$Date, subSetData$Time, sep=" "), "%d/%m/%Y %H:%M:%S") +globalActivePower <- as.numeric(subSetData$Global_active_power) +globalReactivePower <- as.numeric(subSetData$Global_reactive_power) +voltage <- as.numeric(subSetData$Voltage) +subMetering1 <- as.numeric(subSetData$Sub_metering_1) +subMetering2 <- as.numeric(subSetData$Sub_metering_2) +subMetering3 <- as.numeric(subSetData$Sub_metering_3) + + +png("plot4.png", width=480, height=480) +par(mfrow = c(2, 2)) + +plot(datetime, globalActivePower, type="l", xlab="", ylab="Global Active Power", cex=0.2) + +plot(datetime, voltage, type="l", xlab="datetime", ylab="Voltage") + +plot(datetime, subMetering1, type="l", ylab="Energy Submetering", xlab="") +lines(datetime, subMetering2, type="l", col="red") +lines(datetime, subMetering3, type="l", col="blue") +legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty=, lwd=2.5, col=c("black", "red", "blue"), bty="o") + +plot(datetime, globalReactivePower, type="l", xlab="datetime", ylab="Global_reactive_power") + +dev.off() \ No newline at end of file diff --git a/plot4.png b/plot4.png new file mode 100644 index 00000000000..4abb8f38c7e Binary files /dev/null and b/plot4.png differ