diff --git a/plot1.R b/plot1.R new file mode 100644 index 0000000000..e0256878b8 --- /dev/null +++ b/plot1.R @@ -0,0 +1,8 @@ +data = read.csv("./household_power_consumption.txt", header = TRUE, sep = ";", + na.strings = '?') +data$Date <- as.Date(data$Date, format = "%d/%m/%Y") +df<- data[which(data$Date == "2007-02-01" | data$Date == "2007-02-02"),] + +png("plot1.png",width = 480, height = 480, units = "px") +hist(df$Global_active_power) +dev.off() diff --git a/plot1.png b/plot1.png new file mode 100644 index 0000000000..a6dd2926a8 Binary files /dev/null and b/plot1.png differ diff --git a/plot2.R b/plot2.R new file mode 100644 index 0000000000..4c6d4dae8a --- /dev/null +++ b/plot2.R @@ -0,0 +1,9 @@ + +data = read.csv("./household_power_consumption.txt", header = TRUE, sep = ";", + na.strings = '?') +data$Date <- as.Date(data$Date, format = "%d/%m/%Y") +df<- data[which(data$Date == "2007-02-01" | data$Date == "2007-02-02"),] +png("plot2.png",width = 480, height = 480, units = "px") +plot(df$Global_active_power,type= "l",xlab="",xaxt= "n") +axis(1, at = c(0,1441,2881), labels = c("Thu","Fri","Sat")) +dev.off() diff --git a/plot2.png b/plot2.png new file mode 100644 index 0000000000..0d0fecbab4 Binary files /dev/null and b/plot2.png differ diff --git a/plot3.R b/plot3.R new file mode 100644 index 0000000000..b3a7842184 --- /dev/null +++ b/plot3.R @@ -0,0 +1,11 @@ +data = read.csv("./household_power_consumption.txt", header = TRUE, sep = ";", + na.strings = '?') +data$Date <- as.Date(data$Date, format = "%d/%m/%Y") +df<- data[which(data$Date == "2007-02-01" | data$Date == "2007-02-02"),] +png("plot3.png",width = 480, height = 480, units = "px") +plot(df$Sub_metering_1,type= "l",xlab="",xaxt= "n",ylab = "Energy sub metering") +axis(1, at = c(0,1441,2881), labels = c("Thu","Fri","Sat")) +lines(df$Sub_metering_2,xlab = "",xaxt = "n", col= "red") +lines(df$Sub_metering_3,xlab = "",xaxt = "n", col= "blue") +legend("topright",legend = c("sub_metering_1","sub_metering_2","sub_metering_3"),lty = 1, col = c("black","red","blue")) +dev.off() diff --git a/plot3.png b/plot3.png new file mode 100644 index 0000000000..861ae18c5f Binary files /dev/null and b/plot3.png differ diff --git a/plot4.R b/plot4.R new file mode 100644 index 0000000000..2be21dfe9f --- /dev/null +++ b/plot4.R @@ -0,0 +1,19 @@ +data = read.csv("./household_power_consumption.txt", header = TRUE, sep = ";", + na.strings = '?') +data$Date <- as.Date(data$Date, format = "%d/%m/%Y") +df<- data[which(data$Date == "2007-02-01" | data$Date == "2007-02-02"),] + +png("plot4.png",width = 480, height = 480, units = "px") +par(mfrow = c(2,2)) +plot(df$Global_active_power, type = "l",xlab="",xaxt="n",ylab = "Global Active Power") +axis(1, at = c(0,1441,2881), labels = c("Thu","Fri","Sat")) +plot(df$Voltage,type = "l",xlab = "datetime",xaxt = "n", ylab="Voltage") +axis(1, at = c(0,1441,2881), labels = c("Thu","Fri","Sat")) +plot(df$Sub_metering_1,type= "l",xlab="",xaxt= "n",ylab = "Energy sub metering") +axis(1, at = c(0,1441,2881), labels = c("Thu","Fri","Sat")) +lines(df$Sub_metering_2,xlab = "",xaxt = "n", col= "red") +lines(df$Sub_metering_3,xlab = "",xaxt = "n", col= "blue") +legend("topright",legend = c("sub_metering_1","sub_metering_2","sub_metering_3"),lty = 1, col = c("black","red","blue")) +plot(df$Global_reactive_power,type = "l",xlab = "datetime",xaxt = "n",ylab= "Global_reactive_Power") +axis(1, at = c(0,1441,2881), labels = c("Thu","Fri","Sat")) +dev.off() diff --git a/plot4.png b/plot4.png new file mode 100644 index 0000000000..a6c1dfbce4 Binary files /dev/null and b/plot4.png differ