Skip to content

Commit

Permalink
Add plots and generators scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
olegshtch committed Jul 12, 2015
1 parent 73fe5c6 commit e205908
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 0 deletions.
13 changes: 13 additions & 0 deletions plot1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
get_data <- function() {
t <- read.csv("household_power_consumption.txt", header = TRUE, sep = ";"
, na.strings = "?")
t[t$Date == "1/2/2007" | t$Date == "2/2/2007", ]

}

x <- get_data()
Sys.setlocale(category = "LC_ALL", locale = "en_US")
png("plot1.png", 480, 480)
hist(x$Global_active_power, main = "Global Active Power", col = "red"
, 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.
15 changes: 15 additions & 0 deletions plot2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
get_data <- function() {
t <- read.csv("household_power_consumption.txt", header = TRUE, sep = ";"
, na.strings = "?")
t[t$Date == "1/2/2007" | t$Date == "2/2/2007", ]

}

x <- get_data()
x$DT <- strptime(paste(as.character(x$Date),as.character(x$Time), sep = " ")
, format = "%d/%m/%Y %H:%M:%S")
Sys.setlocale(category = "LC_ALL", locale = "en_US")
png("plot2.png", 480, 480)
plot(x$DT, x$Global_active_power, 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.
23 changes: 23 additions & 0 deletions plot3.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
get_data <- function() {
t <- read.csv("household_power_consumption.txt", header = TRUE, sep = ";"
, na.strings = "?")
t[t$Date == "1/2/2007" | t$Date == "2/2/2007", ]

}

x <- get_data()
x$DT <- strptime(paste(as.character(x$Date),as.character(x$Time), sep = " ")
, format = "%d/%m/%Y %H:%M:%S")
Sys.setlocale(category = "LC_ALL", locale = "en_US")
png("plot3.png", 480, 480)
plot(x$DT, x$Sub_metering_1, type = "n", xlab = ""
, ylab = "Energy sub metering")
lines(x$DT, x$Sub_metering_1, col = "black")
lines(x$DT, x$Sub_metering_2, col = "red")
lines(x$DT, x$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)

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.
40 changes: 40 additions & 0 deletions plot4.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
get_data <- function() {
t <- read.csv("household_power_consumption.txt", header = TRUE, sep = ";"
, na.strings = "?")
t[t$Date == "1/2/2007" | t$Date == "2/2/2007", ]

}

x <- get_data()
x$DT <- strptime(paste(as.character(x$Date),as.character(x$Time), sep = " ")
, format = "%d/%m/%Y %H:%M:%S")

Sys.setlocale(category = "LC_ALL", locale = "en_US")
png("plot4.png", 480, 480)
par(mfrow = c(2, 2))

# first
plot(x$DT, x$Global_active_power, type = "l"
, ylab = "Global Active Power", xlab = "")

#second
plot(x$DT, x$Voltage, type = "l"
, ylab = "Voltage", xlab = "datetime")

# third
plot(x$DT, x$Sub_metering_1, type = "n", xlab = ""
, ylab = "Energy sub metering")
lines(x$DT, x$Sub_metering_1, col = "black")
lines(x$DT, x$Sub_metering_2, col = "red")
lines(x$DT, x$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")

#forth
plot(x$DT, x$Global_reactive_power, type = "l"
, ylab = "Global_reactive_power", xlab = "datetime")

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.

0 comments on commit e205908

Please sign in to comment.