Skip to content

Project Finished #990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
Data
ExData_Plotting1.Rproj
25 changes: 25 additions & 0 deletions plot1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# download and read the data
url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download.file(url = url, destfile = "Data/ElectricPowerConsumption.zip", mode = 'wb')

dir.create("Data")
setwd("Data")
unzip(zipfile = "ElectricPowerConsumption.zip")
setwd ("..")

data <- read.table("Data/household_power_consumption.txt", sep = ";", header = TRUE, na.strings = '?')

# select only the data from 2007-02-01 and 2007-02-02
data$Date <- as.Date(data$Date, format = "%d/%m/%Y")
data <- data[(data$Date >= "2007-02-01") & (data$Date <= "2007-02-02"), ]

# convert the variable Global active power to data type numeric
data$Global_active_power <- as.numeric(data$Global_active_power)

png(filename = "plot1.png", width = 480, height = 480, units = "px")
hist(data$Global_active_power, col = "red", main = "Global Active Power",
xlab = "Global Active Power (kilowatts)")
dev.off()



Binary file added plot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions plot2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# download and read the data
url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download.file(url = url, destfile = "Data/ElectricPowerConsumption.zip", mode = 'wb')

dir.create("Data")
setwd("Data")
unzip(zipfile = "ElectricPowerConsumption.zip")
setwd ("..")

data <- read.table("Data/household_power_consumption.txt", sep = ";", header = TRUE, na.strings = '?')

# select only the data from 2007-02-01 and 2007-02-02
data$DateTime <- as.POSIXct(paste(data$Date, data$Time), format = "%d/%m/%Y %H:%M:%S")
data <- data[(data$DateTime >= "2007-02-01") & (data$DateTime < "2007-02-03"), ]


# convert the variable Global active power to data type numeric
data$Global_active_power <- as.numeric(data$Global_active_power)


png(filename = "plot2.png", width = 480, height = 480, units = "px")
plot(x = data$DateTime, y = data$Global_active_power, pch = ".", xlab = ""
, ylab = "Global Active Power (kilowatts)")
lines(data$DateTime, data$Global_active_power)
dev.off()
Binary file added plot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions plot3.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# download and read the data
url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download.file(url = url, destfile = "Data/ElectricPowerConsumption.zip", mode = 'wb')

dir.create("Data")
setwd("Data")
unzip(zipfile = "ElectricPowerConsumption.zip")
setwd ("..")

data <- read.table("Data/household_power_consumption.txt", sep = ";", header = TRUE, na.strings = '?')

# select only the data from 2007-02-01 and 2007-02-02
data$DateTime <- as.POSIXct(paste(data$Date, data$Time), format = "%d/%m/%Y %H:%M:%S")
data <- data[(data$DateTime >= "2007-02-01") & (data$DateTime < "2007-02-03"), ]


png(filename = "plot3.png", width = 480, height = 480, units = "px")
plot(x = data$DateTime, y = data$Sub_metering_1, pch = ".", xlab = "",
ylab = "Energy sub metering")
lines(x = data$DateTime, y = data$Sub_metering_1, col = "black")
lines(x = data$DateTime, y = data$Sub_metering_2, col = "red")
lines(x = data$DateTime, y = data$Sub_metering_3, col = "blue")
legend("topright", col = c("black", "red", "blue"), lty = c(1, 1),
legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
dev.off()
Binary file added plot3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions plot4.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# download and read the data
url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download.file(url = url, destfile = "Data/ElectricPowerConsumption.zip", mode = 'wb')

dir.create("Data")
setwd("Data")
unzip(zipfile = "ElectricPowerConsumption.zip")
setwd ("..")

data <- read.table("Data/household_power_consumption.txt", sep = ";", header = TRUE, na.strings = '?')

# select only the data from 2007-02-01 and 2007-02-02
data$DateTime <- as.POSIXct(paste(data$Date, data$Time), format = "%d/%m/%Y %H:%M:%S")
data <- data[(data$DateTime >= "2007-02-01") & (data$DateTime < "2007-02-03"), ]


png(filename = "plot4.png", width = 480, height = 480, units = "px")
# set the number of plots per row
par(mfrow = c(2, 2), mar = c(4, 4, 2, 1))
# plot 1
plot(x = data$DateTime, y = data$Global_active_power, pch = ".", xlab = ""
, ylab = "Global Active Power (kilowatts)")
lines(data$DateTime, data$Global_active_power)

# plot 2
plot(x = data$DateTime, y = data$Voltage, pch = ".", xlab = "datetime"
, ylab = "Voltage")
lines(data$DateTime, data$Voltage)

# plot 3
plot(x = data$DateTime, y = data$Sub_metering_1, pch = ".", xlab = "",
ylab = "Energy sub metering")
lines(x = data$DateTime, y = data$Sub_metering_1, col = "black")
lines(x = data$DateTime, y = data$Sub_metering_2, col = "red")
lines(x = data$DateTime, y = data$Sub_metering_3, col = "blue")
legend("topright", col = c("black", "red", "blue"), lty = c(1, 1),
legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), bty = "n", cex = .5)

# plot 4

plot(x = data$DateTime, y = data$Global_reactive_power, pch = ".", xlab = "datetime"
, ylab = "Global Reactive Power")
lines(data$DateTime, data$Global_reactive_power)
dev.off()
Binary file added plot4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.