Skip to content

EDA Assignment Plots #1026

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
11 changes: 11 additions & 0 deletions plot1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Create Plot 1
png("plot1.png", width = 480, height = 480)

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

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.
17 changes: 17 additions & 0 deletions plot2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Load data
data <- read.table("household_power_consumption.txt", header=TRUE, sep=";", na.strings="?", stringsAsFactors=FALSE)
data$Date <- as.Date(data$Date, format="%d/%m/%Y")
data$DateTime <- strptime(paste(data$Date, data$Time), format="%Y-%m-%d %H:%M:%S")

# Subset data
data_subset <- subset(data, Date >= as.Date("2007-02-01") & Date <= as.Date("2007-02-02"))

# Create PNG file
png("plot2.png", width=480, height=480)

# Create line plot
plot(data_subset$DateTime, data_subset$Global_active_power, type="l",
xlab="", ylab="Global Active Power (kilowatts)")

# Close file
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 @@
# Load data
data <- read.table("household_power_consumption.txt", header=TRUE, sep=";", na.strings="?", stringsAsFactors=FALSE)
data$Date <- as.Date(data$Date, format="%d/%m/%Y")
data$DateTime <- strptime(paste(data$Date, data$Time), format="%Y-%m-%d %H:%M:%S")

# Subset data
data_subset <- subset(data, Date >= as.Date("2007-02-01") & Date <= as.Date("2007-02-02"))

# Create PNG file
png("plot3.png", width=480, height=480)

# Create multi-line plot
plot(data_subset$DateTime, data_subset$Sub_metering_1, type="l", col="black",
xlab="", ylab="Energy sub metering")
lines(data_subset$DateTime, data_subset$Sub_metering_2, col="red")
lines(data_subset$DateTime, data_subset$Sub_metering_3, col="blue")

# Add legend
legend("topright",
legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
col=c("black", "red", "blue"), lty=1)

# Close file
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.
37 changes: 37 additions & 0 deletions plot4.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Load data
data <- read.table("household_power_consumption.txt", header=TRUE, sep=";", na.strings="?", stringsAsFactors=FALSE)
data$Date <- as.Date(data$Date, format="%d/%m/%Y")
data$DateTime <- strptime(paste(data$Date, data$Time), format="%Y-%m-%d %H:%M:%S")

# Subset data
data_subset <- subset(data, Date >= as.Date("2007-02-01") & Date <= as.Date("2007-02-02"))

# Create PNG file
png("plot4.png", width=480, height=480)

# Set up a 2x2 plot layout
par(mfrow=c(2,2))

# Plot 1 (Top left) - Global Active Power
plot(data_subset$DateTime, data_subset$Global_active_power, type="l",
xlab="", ylab="Global Active Power")

# Plot 2 (Top right) - Voltage
plot(data_subset$DateTime, data_subset$Voltage, type="l",
xlab="datetime", ylab="Voltage")

# Plot 3 (Bottom left) - Energy sub-metering
plot(data_subset$DateTime, data_subset$Sub_metering_1, type="l", col="black",
xlab="", ylab="Energy sub metering")
lines(data_subset$DateTime, data_subset$Sub_metering_2, col="red")
lines(data_subset$DateTime, data_subset$Sub_metering_3, col="blue")
legend("topright", legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
col=c("black", "red", "blue"), lty=1, bty="n")

# Plot 4 (Bottom right) - Global Reactive Power
plot(data_subset$DateTime, data_subset$Global_reactive_power, type="l",
xlab="datetime", ylab="Global Reactive Power")

# Close file
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.