diff --git a/plot1.R b/plot1.R new file mode 100644 index 00000000000..05c07d58911 --- /dev/null +++ b/plot1.R @@ -0,0 +1,17 @@ +dat<-read.csv("household_power_consumption.txt", sep=";", header = TRUE) + +times<-strptime(paste(dat$Date,dat$Time), format = "%d/%m/%Y %H:%M:%S") + +date=data.frame(as.Date(dat$Date, "%d/%m/%Y")) + +dat$Date=as.Date(dat$Date, "%d/%m/%Y") + +dat$newtimes=times + +dat2<-dat[dat$Date>= "2007-02-01",] + +dat3<-dat2[dat2$Date <= "2007-02-02",] + +hist(as.numeric(dat3$Global_active_power), col = "red", xlab = "Global Active Power (kilowatts)", main = "Global Active Power") +dev.copy(png,'plot1.png') +dev.off() \ No newline at end of file diff --git a/plot1.png b/plot1.png new file mode 100644 index 00000000000..db485ff3905 Binary files /dev/null and b/plot1.png differ diff --git a/plot2.R b/plot2.R new file mode 100644 index 00000000000..44d47742fcd --- /dev/null +++ b/plot2.R @@ -0,0 +1,17 @@ +dat<-read.csv("household_power_consumption.txt", sep=";", header = TRUE) + +times<-strptime(paste(dat$Date,dat$Time), format = "%d/%m/%Y %H:%M:%S") + +date=data.frame(as.Date(dat$Date, "%d/%m/%Y")) + +dat$Date=as.Date(dat$Date, "%d/%m/%Y") + +dat$newtimes=times + +dat2<-dat[dat$Date>= "2007-02-01",] + +dat3<-dat2[dat2$Date <= "2007-02-02",] + +plot(dat3$newtimes,dat3$Global_active_power, type="l", ylab = "Global Active Power (kilowatts)") +dev.copy(png,'plot2.png') +dev.off() \ No newline at end of file diff --git a/plot2.png b/plot2.png new file mode 100644 index 00000000000..b25d24a9d62 Binary files /dev/null and b/plot2.png differ diff --git a/plot3.R b/plot3.R new file mode 100644 index 00000000000..b78f1b5e7fc --- /dev/null +++ b/plot3.R @@ -0,0 +1,20 @@ +dat<-read.csv("household_power_consumption.txt", sep=";", header = TRUE) + +times<-strptime(paste(dat$Date,dat$Time), format = "%d/%m/%Y %H:%M:%S") + +date=data.frame(as.Date(dat$Date, "%d/%m/%Y")) + +dat$Date=as.Date(dat$Date, "%d/%m/%Y") + +dat$newtimes=times + +dat2<-dat[dat$Date>= "2007-02-01",] + +dat3<-dat2[dat2$Date <= "2007-02-02",] + +plot(dat3$newtimes,dat3$Sub_metering_1, type="l", ylab = "Energy sub metering") +points(dat3$newtimes,dat3$Sub_metering_2, type = "l", col = "red") +points(dat3$newtimes,dat3$Sub_metering_3, type="l", col = "blue") +legend(x ="topright", legend = c("Sub_metering_1","Sub_metering_2","Sub_metering_3"), col = c("black", "red", "blue"), lty = 1, lwd=2) +dev.copy(png,'plot3.png') +dev.off() \ No newline at end of file diff --git a/plot3.png b/plot3.png new file mode 100644 index 00000000000..d1118939cb9 Binary files /dev/null and b/plot3.png differ diff --git a/plot4.R b/plot4.R new file mode 100644 index 00000000000..fecd7d731c8 --- /dev/null +++ b/plot4.R @@ -0,0 +1,24 @@ +dat<-read.csv("household_power_consumption.txt", sep=";", header = TRUE) + +times<-strptime(paste(dat$Date,dat$Time), format = "%d/%m/%Y %H:%M:%S") + +date=data.frame(as.Date(dat$Date, "%d/%m/%Y")) + +dat$Date=as.Date(dat$Date, "%d/%m/%Y") + +dat$newtimes=times + +dat2<-dat[dat$Date>= "2007-02-01",] + +dat3<-dat2[dat2$Date <= "2007-02-02",] + +par(mfrow=c(2,2)) +plot(dat3$newtimes,dat3$Global_active_power, type="l", ylab = "Global Active Power", xlab = "") +plot(dat3$newtimes,dat3$Voltage, type="l", ylab = "Voltage", xlab = "") +plot(dat3$newtimes,dat3$Sub_metering_1, type="l", ylab = "Energy sub metering", xlab = "") +points(dat3$newtimes,dat3$Sub_metering_2, type = "l", col = "red") +points(dat3$newtimes,dat3$Sub_metering_3, type="l", col = "blue") +legend(x ="top", legend = c("Sub_metering_1","Sub_metering_2","Sub_metering_3"), bty = "n", col = c("black", "red", "blue"), lty = 1, lwd=2) +plot(dat3$newtimes,dat3$Global_reactive_power, type="l", ylab = "Global Reactive Power", xlab = "") +dev.copy(png,'plot4.png') +dev.off() \ No newline at end of file diff --git a/plot4.png b/plot4.png new file mode 100644 index 00000000000..b96711ebf92 Binary files /dev/null and b/plot4.png differ