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
34 lines (26 loc) · 1.4 KB
/
Copy pathplot4.R
File metadata and controls
34 lines (26 loc) · 1.4 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
# Downloads and reads data
source('./getdata.R')
# sets to 2x2 plots
par(mfrow = c(2,2))
# Plots to plot4.png
# png("plot4.png") <-- this doesn't create 2x2 plots for some reason; using dev.copy() below
# First plot: global active power across time
plot(subdata$DateTime, subdata$Global_active_power, xlab="", ylab="Global Active Power", type="n")
lines(subdata$DateTime, subdata$Global_active_power, col="black")
# Second plot: voltage across time
plot(subdata$DateTime, subdata$Voltage, xlab="datatime", ylab="Voltage", type="n")
lines(subdata$DateTime, subdata$Voltage, col="black")
# Third plot: sub metering
plot(subdata$DateTime, subdata$Sub_metering_1, xlab="", ylab="Energy sub metering", type="n")
## plot the line graphs
lines(subdata$DateTime, subdata$Sub_metering_1, col="black")
lines(subdata$DateTime, subdata$Sub_metering_2, col="red")
lines(subdata$DateTime, subdata$Sub_metering_3, col="blue")
## create legend
legend("topright", lty=c(1,1,1), col=c("black", "red", "blue"), legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
# Fourth plot: global reactive power across time
plot(subdata$DateTime, subdata$Global_reactive_power, xlab="datatime", ylab="Global_reactive_power", type="n")
lines(subdata$DateTime, subdata$Global_reactive_power, col="black")
# plotting directly to png() only seems to create the last plot; using dev.copy() to get around it
dev.copy(png, "plot4.png")
dev.off()