diff --git a/Plot1.png b/Plot1.png new file mode 100644 index 00000000000..10bebc15799 Binary files /dev/null and b/Plot1.png differ diff --git a/plot1.R b/plot1.R new file mode 100644 index 00000000000..655654de302 --- /dev/null +++ b/plot1.R @@ -0,0 +1,6 @@ +#read the table +my_data <- read.table("household_power_consumption.txt", sep = ";", header = TRUE) +subset <- my_data[my_data$Date %in% c("1/2/2007", "2/2/2007"),] +subset$"Global_active_power" <- as.numeric(subset$"Global_active_power") +#plot the graph +hist(subset$"Global_active_power",col="red", main="Global Active Power", xlab="Global Active Power (kilowatts)") \ No newline at end of file diff --git a/plot2.R b/plot2.R new file mode 100644 index 00000000000..fcd2d186dd0 --- /dev/null +++ b/plot2.R @@ -0,0 +1,7 @@ +data <- read.table(file.choose(), sep=";", header=TRUE) +data$Date <- as.Date(data$Date, format = '%d/%m/%Y') +data$DateTime <- as.POSIXct(paste(data$Date, data$Time)) +if(!file.exists('figures')) dir.create('figures') +png(filename = './figures/plot2.png', width = 480, height = 480, units='px') +plot(data$DateTime, data$Global_active_power, xlab = '', ylab = 'Global Active Power (kilowatt)', type = 'l') + diff --git a/plot2.png b/plot2.png new file mode 100644 index 00000000000..6ba031134ac Binary files /dev/null and b/plot2.png differ diff --git a/plot3.R b/plot3.R new file mode 100644 index 00000000000..ec7a553225c --- /dev/null +++ b/plot3.R @@ -0,0 +1,7 @@ +my_data <- read.table("household_power_consumption.txt", sep = ";", header = TRUE) +data <- my_data[my_data$Date %in% c("1/2/2007", "2/2/2007"),] +png(filename = './figures/plot3.png', width = 480, height = 480, units='px') +plot(data$DateTime, data$Sub_metering_1, xlab = '', ylab = 'Energy sub metering', type = 'l') +lines(data$DateTime, data$Sub_metering_2, col = 'red') +lines(data$DateTime, data$Sub_metering_3, col = 'blue') +legend('topright', col = c('black', 'red', 'blue'), legend = c('Sub_metering_1', 'Sub_metering_2', 'Sub_metering_3'), lwd = 1) \ No newline at end of file diff --git a/plot3.png b/plot3.png new file mode 100644 index 00000000000..aaf617fdc70 Binary files /dev/null and b/plot3.png differ diff --git a/plot4.R b/plot4.R new file mode 100644 index 00000000000..66bf8820b58 --- /dev/null +++ b/plot4.R @@ -0,0 +1,11 @@ +my_data <- read.table("household_power_consumption.txt", sep = ";", header = TRUE) +data <- my_data[my_data$Date %in% c("1/2/2007", "2/2/2007"),] +png(filename = './figures/plot4.png', width = 480, height = 480, units='px') +par(mfrow = c(2, 2)) +plot(data$DateTime, data$Global_active_power, xlab = '', ylab = 'Global Active Power (kilowatt)', type = 'l') +plot(data$DateTime, data$Voltage, xlab = 'datetime', ylab = 'Voltage', type = 'l') +plot(data$DateTime, data$Sub_metering_1, xlab = '', ylab = 'Energy sub metering', type = 'l') +lines(data$DateTime, data$Sub_metering_2, col = 'red') +lines(data$DateTime, data$Sub_metering_3, col = 'blue') +legend('topright', col = c('black', 'red', 'blue'), legend = c('Sub_metering_1', 'Sub_metering_2', 'Sub_metering_3'), lwd = 1) +plot(data$DateTime, data$Global_reactive_power, 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..583d2722459 Binary files /dev/null and b/plot4.png differ