forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot4.R
More file actions
35 lines (33 loc) · 1.85 KB
/
Copy pathPlot4.R
File metadata and controls
35 lines (33 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Zipfile <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download.file(Zipfile, destfile = "./Zipfile.zip", method = "curl")
list.files("./")
unzip("./Zipfile.zip")
file.remove("./Zipfile.zip")
install.packages("readr","tidyverse","lubridate")
library(readr, tidyverse, lubridate)
dateDownloaded <- date()
dateDownloaded
consraw <- read_delim("./household_power_consumption.txt", delim = ";")
consraw$Date <- as.Date(consraw$Date, format = "%d/%m/%Y")
cons <- consraw %>%
filter(Date >= as.Date("2007-02-01") & Date <= as.Date("2007-02-02"))
remove(consraw)
cons$weekday <- weekdays(cons$Date)
png(filename = "Rplot4.png",
width = 480, height = 480, units = "px", pointsize = 12, bg = "grey")
par( mfrow = c(2,2), mar = c(2,2,2,2), oma = c(1,1,1,1))
plot(cons$Global_active_power, type = "l", ylab = "Global Active Power (kilowatts)", xaxt = "n", xlab = "")
axis(1, at = c(0, 1440, 2880), labels = (c("Thu","Fri","Sat")))
plot(cons$Voltage, type = "l", ylab = "Voltage", xaxt = "n", xlab = "")
axis(1, at = c(0, 1440, 2880), labels = (c("Thu","Fri","Sat")))
plot(cons$Sub_metering_1, type = "l", ylab = "Energy sub metering", xaxt = "n", xlab = "")
lines(cons$Sub_metering_2, col = "red")
lines(cons$Sub_metering_3, col = "blue")
axis(1, at = c(0, 1440, 2880), labels = (c("Thu","Fri","Sat")))
legend("topright",
legend = c("sub metering 1","sub metering 2", "sub metering 3"),
col = c("black","red","blue"),
lty = c(1,1,1))
plot(cons$Global_reactive_power, type = "l", ylab = "Global reactive Power (kilowatts)", xaxt = "n", xlab = "")
axis(1, at = c(0, 1440, 2880), labels = (c("Thu","Fri","Sat")))
dev.off()