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
27 lines (26 loc) · 1.26 KB
/
plot4.R
File metadata and controls
27 lines (26 loc) · 1.26 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
# Plot 4
# open device
if(!file.exists("Graphics")) dir.create("Graphics")
png(filename = "./Graphics/plot4.png", width = 480, height = 480, units="px")
# plot figure
Sys.setlocale(category = "LC_ALL", locale = "english")
par(mfrow = c(2, 2))
plot(data$DateTime, data$Global_active_power, xlab = "",
ylab = "Global Active Power (kilowatt)",
type = "l")
plot(data$DateTime, data$Voltage, xlab = "datetime",
ylab = "Voltage",
type = "l")
plot(data$DateTime, data$Sub_metering_1, xlab = "",
ylab = "Energy sub metering",
type = "l")
lines(data$DateTime, data$Sub_metering_2, col = "red")
lines(data$DateTime, data$Sub_metering_3, col = "blue")
legend("topright", col = c("black", "red", "blue"),
legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
lwd = 1)
plot(data$DateTime, data$Global_reactive_power, xlab = "datetime",
ylab = "Global_reactive_power",
type = "l")
# close device
dev.off()