diff --git a/plot1.R b/plot1.R new file mode 100644 index 00000000000..ad051655df0 --- /dev/null +++ b/plot1.R @@ -0,0 +1,7 @@ +electric <- read.csv("household_power_consumption.txt", header = TRUE, sep = ';') +electric <- subset(electric, (electric$Date == "1/2/2007")|(electric$Date == "2/2/2007")) +electric$Global_active_power <- as.numeric(electric$Global_active_power) +png("plot1.png", width = 480, height = 480) +hist(electric$Global_active_power, xlab = "Global Active Power (kilowatts)", col = "red") +dev.off() + diff --git a/plot1.png b/plot1.png new file mode 100644 index 00000000000..0e023ca1e88 Binary files /dev/null and b/plot1.png differ diff --git a/plot2.R b/plot2.R new file mode 100644 index 00000000000..ae793846ccf --- /dev/null +++ b/plot2.R @@ -0,0 +1,6 @@ +electric <- read.csv("household_power_consumption.txt", header = TRUE, sep = ';') +electric <- subset(electric, (electric$Date == "1/2/2007")|(electric$Date == "2/2/2007")) +Datetime <- strptime(paste(electric$Date, electric$Time), "%d/%m/%Y %H:%M:%S") +png("plot2.png", width = 480, height = 480) +plot(Datetime, electric$Global_active_power, xlab = "", ylab = "Global Active Power (kilowatts)", type='l') +dev.off() diff --git a/plot2.png b/plot2.png new file mode 100644 index 00000000000..c78fd517c53 Binary files /dev/null and b/plot2.png differ diff --git a/plot3.R b/plot3.R new file mode 100644 index 00000000000..6a5ef0aceaf --- /dev/null +++ b/plot3.R @@ -0,0 +1,9 @@ +electric <- read.csv("household_power_consumption.txt", header = TRUE, sep = ';') +electric <- subset(electric, (electric$Date == "1/2/2007")|(electric$Date == "2/2/2007")) +Datetime <- strptime(paste(electric$Date, electric$Time), "%d/%m/%Y %H:%M:%S") +png("plot3.png", width = 480, height = 480) +plot(Datetime, electric$Sub_metering_1, xlab = "", ylab = "Energy sub metering", type='l') +lines(Datetime, electric$Sub_metering_2, xlab = "", ylab = "Energy sub metering", type='l', col="red") +lines(Datetime, electric$Sub_metering_3, xlab = "", ylab = "Energy sub metering", type='l', col="blue") +legend("topright", legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), col=c("black", "red", "blue"), lty=1, cex=1) +dev.off() diff --git a/plot3.png b/plot3.png new file mode 100644 index 00000000000..6ba09e487e7 Binary files /dev/null and b/plot3.png differ diff --git a/plot4.R b/plot4.R new file mode 100644 index 00000000000..48bf00df1ac --- /dev/null +++ b/plot4.R @@ -0,0 +1,14 @@ +electric <- read.csv("household_power_consumption.txt", header = TRUE, sep = ';') +electric <- subset(electric, (electric$Date == "1/2/2007")|(electric$Date == "2/2/2007")) +electric$Global_active_power <- as.numeric(electric$Global_active_power) +Datetime <- strptime(paste(electric$Date, electric$Time), "%d/%m/%Y %H:%M:%S") +png("plot4.png", width = 480, height = 480) +par(mfrow = c(2,2)) +plot(Datetime, electric$Global_active_power, xlab = "", ylab = "Global Active Power", type='l') +plot(Datetime, electric$Voltage, xlab = "", ylab = "Voltage", type='l') +plot(Datetime, electric$Sub_metering_1, xlab = "", ylab = "Energy sub metering", type='l') +lines(Datetime, electric$Sub_metering_2, xlab = "", ylab = "Energy sub metering", type='l', col="red") +lines(Datetime, electric$Sub_metering_3, xlab = "", ylab = "Energy sub metering", type='l', col="blue") +legend("topright", legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), col=c("black", "red", "blue"), lty=1, cex=1, box.lty=0) +plot(Datetime, electric$Global_reactive_power, xlab = "datetime", ylab = "Global_reactive_power", type='l') +dev.off() diff --git a/plot4.png b/plot4.png new file mode 100644 index 00000000000..ed2d8e13546 Binary files /dev/null and b/plot4.png differ