Skip to content
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

Add files via upload #1004

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
43 changes: 43 additions & 0 deletions plot1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
##Make sure to download and unzip the file (Source = https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip)
##set your working directory and check that "household_power_consumption.txt" is located inside
##list.files() = "household_power_consumption.txt"


##Read in the "household_power_consumption.txt"
Full_Data_Frame <- read.table("household_power_consumption.txt",
header = T,
sep = ';',
na.strings = "?",
nrows = 2075259,
check.names = F,
stringsAsFactors = F,
comment.char = "",
quote = '\"')


##Subsett just the two days we need ("1/2/2007" & "2/2/2007")
Data <- subset(Full_Data_Frame,
Date %in% c("1/2/2007",
"2/2/2007"))


##Convert Date & Time
Data$Date <- as.Date(Data$Date,
format = "%d/%m/%Y")

Data$Time <- format(Data$Time,
format = "%H:%M:%S")


##Plot & save the histogram of "Global Active Power" as a png
png("plot1.png",
width = 480,
height = 480)

hist(Data$Global_active_power,
main = "Global Active Power",
xlab = "Global Active Power (kilowatts)",
ylab = "Frequency",
col = "Red")

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.
53 changes: 53 additions & 0 deletions plot2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
##Make sure to download and unzip the file (Source = https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip)
##set your working directory and check that "household_power_consumption.txt" is located inside
##list.files() = "household_power_consumption.txt"


##Read in the "household_power_consumption.txt"
Full_Data_Frame <- read.table("household_power_consumption.txt",
header = T,
sep = ';',
na.strings = "?",
nrows = 2075259,
check.names = F,
stringsAsFactors = F,
comment.char = "",
quote = '\"')


##Subsett just the two days we need ("1/2/2007" & "2/2/2007")
Data <- subset(Full_Data_Frame,
Date %in% c("1/2/2007",
"2/2/2007"))


##Convert Date & Time
Data$Date <- as.Date(Data$Date,
format = "%d/%m/%Y")

Data$Time <- format(Data$Time,
format = "%H:%M:%S")


##Combine $Date & $Time
Date_Time <- paste(as.Date(Data$Date),
Data$Time)


##Convert "Date_Time" to POSIXct and add it to "Data" as a new column
Data$Date_Time <- as.POSIXct(Date_Time)


##Plot "Date_Time" & "Global_active_power"
png("plot2.png",
width = 480,
height = 480)

with(Data,
{ plot(Global_active_power~Date_Time,
type = "l",
ylab = "Global Active Power (kilowatts)",
xlab = "") }
)

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.
71 changes: 71 additions & 0 deletions plot3.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
##Make sure to download and unzip the file (Source = https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip)
##set your working directory and check that "household_power_consumption.txt" is located inside
##list.files() = "household_power_consumption.txt"


##Read in the "household_power_consumption.txt"
Full_Data_Frame <- read.table("household_power_consumption.txt",
header = T,
sep = ';',
na.strings = "?",
nrows = 2075259,
check.names = F,
stringsAsFactors = F,
comment.char = "",
quote = '\"')


##Subsett just the two days we need ("1/2/2007" & "2/2/2007")
Data <- subset(Full_Data_Frame,
Date %in% c("1/2/2007",
"2/2/2007"))


##Convert Date & Time
Data$Date <- as.Date(Data$Date,
format = "%d/%m/%Y")

Data$Time <- format(Data$Time,
format = "%H:%M:%S")


##Combine $Date & $Time
Date_Time <- paste(as.Date(Data$Date),
Data$Time)


##Convert "Date_Time" to POSIXct and add it to "Data" as a new column
Data$Date_Time <- as.POSIXct(Date_Time)


##Plot "Date_Time" & "Global_active_power"
png("plot3.png",
width = 480,
height = 480)

with(Data,
{ plot(Sub_metering_1~Date_Time,
type = "l",
ylab = "Energy sub metering",
xlab = "")

lines(Sub_metering_2~Date_Time,
col = 'Red')

lines(Sub_metering_3~Date_Time,
col = 'Blue') }
)

##Add the legend
legend("topright",
col=c("black",
"red",
"blue"),
lty=1,
lwd=2,
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.
93 changes: 93 additions & 0 deletions plot4.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
##Make sure to download and unzip the file (Source = https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip)
##set your working directory and check that "household_power_consumption.txt" is located inside
##list.files() = "household_power_consumption.txt"


##Read in the "household_power_consumption.txt"
Full_Data_Frame <- read.table("household_power_consumption.txt",
header=T, sep=';',
na.strings="?",
nrows=2075259,
check.names=F,
stringsAsFactors=F,
comment.char="",
quote='\"')


##Subsett just the two days we need ("1/2/2007" & "2/2/2007")
Data <- subset(Full_Data_Frame,
Date %in% c("1/2/2007",
"2/2/2007"))


##Convert Date & Time
Data$Date <- as.Date(Data$Date,
format = "%d/%m/%Y")

Data$Time <- format(Data$Time,
format = "%H:%M:%S")


##Combine $Date & $Time
Date_Time <- paste(as.Date(Data$Date),
Data$Time)


##Convert "Date_Time" to POSIXct and add it to "Data" as a new column
Data$Date_Time <- as.POSIXct(Date_Time)


##Save
png("plot4.png",
width = 480,
height = 480)


##Set the parameters for the graphs
par(mfrow = c(2,2),
mar = c(4,4,2,1),
oma = c(0,0,2,0))


##Plotting (Using 1 function)
with(Data,
{ plot(Global_active_power~Date_Time,
type = "l",
ylab = "Global Active Power",
xlab = "")

plot(Voltage~Date_Time,
type = "l",
ylab = "Voltage",
xlab = "")

plot(Sub_metering_1~Date_Time,
type = "l",
ylab = "Energy sub metering",
xlab = "")

lines(Sub_metering_2~Date_Time,
col = 'Red')

lines(Sub_metering_3~Date_Time,
col = 'Blue')

legend("topright",
col = c("black",
"red",
"blue"),
lty=1,
lwd=2,
bty="n",
legend = c("Sub_metering_1",
"Sub_metering_2",
"Sub_metering_3"))

plot(Global_reactive_power~Date_Time,
type = "l",
ylab = "Global_reactive_power",
xlab = "") }
)


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.