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
25 lines (24 loc) · 1.11 KB
/
Copy pathplot4.R
File metadata and controls
25 lines (24 loc) · 1.11 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
#Loading data
pcb <- read.table("../data/household_power_consumption.txt", head=TRUE, sep =";", na.string="?", colClasses=c("character", "character", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric"))
#Subsetting
pcb <- subset(pcb, Date=="1/2/2007"| Date=="2/2/2007")
pcb$datetime <- paste(pcb$Date,pcb$Time)
pcb$datetime <- strptime(pcb$datetime, "%d/%m/%Y %H:%M:%S")
png("plot4.png", width = 480, height = 480, unit = "px", bg = "transparent")
#Creating plot device
par(mfrow=c(2,2))
with(pcb, {
#Left upper
plot(datetime, Global_active_power, type="l",ann=FALSE)
title(ylab="Global Active Power")
#Right upper
plot(datetime, Voltage, type="l",ylab="Voltage")
#Left lower
plot(pcb$datetime, pcb$Sub_metering_1, type="l", ylab="Energy sub metering", xlab="")
lines(pcb$datetime, pcb$Sub_metering_2, col="red")
lines(pcb$datetime, pcb$Sub_metering_3, col="blue")
legend("topright", col=c("black", "blue", "red"), legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lwd=1)
#Right lower
plot(datetime, Global_reactive_power, type="l",ylab="Global_reactive_power")
})
dev.off()