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
50 lines (39 loc) · 1.01 KB
/
Copy pathplot4.R
File metadata and controls
50 lines (39 loc) · 1.01 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require(graphics)
source('get_data.R')
# Read the data
data <- get_data()
# Create a PNG
png(file="plot4.png", width = 480, height = 480, units = "px", bg = "transparent")
par(mfrow=c(2,2))
# Plot 1
plot(data$Date, data$Global_active_power,
type = 'l',
xlab = '',
ylab = 'Global Active Power (kilowatts)')
# Plot 2
plot(data$Date, data$Voltage,
type = 'l',
xlab = 'datetime',
ylab = 'Voltage')
# Plot 3
plot(data$Date, data$Sub_metering_1,
type = 'n',
xlab = '',
ylab = 'Energy sub metering')
# Draw the lines
lines(data$Date, data$Sub_metering_1)
lines(data$Date, data$Sub_metering_2, col = 'red')
lines(data$Date, data$Sub_metering_3, col = 'blue')
# Draw the legend
legend('topright',
c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
col = c("black","red","blue"),
lty = c(1,1),
bty='n')
# Plot 4
plot(data$Date, data$Global_reactive_power,
type = 'l',
xlab = 'datetime',
ylab = 'Global_reactive_power')
# Write result
dev.off()