diff --git a/plot1.R b/plot1.R new file mode 100644 index 00000000000..01679c97805 --- /dev/null +++ b/plot1.R @@ -0,0 +1,6 @@ +file_name <- "household_power_consumption.txt" +data <- read.table(file_name, header = TRUE, sep = ";", dec = ".", na.strings = "?") + +data <- data[data$Date %in% c("1/2/2007","2/2/2007"), ] + +hist(data[,3], col = "red", main = "Global Active Power", xlab = "Global Active Power (kilowatts)") diff --git a/plot1.png b/plot1.png new file mode 100644 index 00000000000..19e748c6eb2 Binary files /dev/null and b/plot1.png differ diff --git a/plot2.R b/plot2.R new file mode 100644 index 00000000000..d02405ca1ba --- /dev/null +++ b/plot2.R @@ -0,0 +1,8 @@ +Sys.setlocale("LC_TIME", "English") +## [1] "English_United States.1252" + +date_converted <- as.Date(data[, 1], format = "%d/%m/%Y") +time_converted <- strptime(data[, 2], format = "%H:%M:%S") +time_axis <- as.POSIXct(paste(date_converted, data[, 2])) + +plot(time_axis, data[, 3], xlab = "", ylab = "Global Active Power (kilowatts)", type = "l") \ No newline at end of file diff --git a/plot2.png b/plot2.png new file mode 100644 index 00000000000..3a96ef81225 Binary files /dev/null and b/plot2.png differ diff --git a/plot3.R b/plot3.R new file mode 100644 index 00000000000..b2e83610979 --- /dev/null +++ b/plot3.R @@ -0,0 +1,5 @@ +plot(time_axis, data[, 7], xlab = "", ylab = "Energy sub metering", type = "l") +lines(time_axis, data[, 8], col = "red") +lines(time_axis, data[, 9], col = "blue") + +legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), col = c("black","red","blue"), lty = 1) \ No newline at end of file diff --git a/plot3.png b/plot3.png new file mode 100644 index 00000000000..96e5fda51ca Binary files /dev/null and b/plot3.png differ diff --git a/plot4.R b/plot4.R new file mode 100644 index 00000000000..c5e78db2939 --- /dev/null +++ b/plot4.R @@ -0,0 +1,14 @@ +par(mfrow = c(2,2)) + +plot(time_axis, data[, 3], xlab = "", ylab = "Global Active Power (kilowatts)", type = "l") + +plot(time_axis, data[, 5], xlab = "datetime", ylab = "Voltage", type = "l") + +plot(time_axis, data[, 7], xlab = "", ylab = "Energy sub metering", type = "l") +lines(time_axis, data[, 8], col = "red") +lines(time_axis, data[, 9], col = "blue") + +legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), + col = c("black","red","blue"), cex = 0.8, lty = 1 , bty = "n") + +plot(time_axis, data[, 4], xlab = "datetime", ylab = "Global_reactive_power", type = "l") \ No newline at end of file diff --git a/plot4.png b/plot4.png new file mode 100644 index 00000000000..37265259e1d Binary files /dev/null and b/plot4.png differ