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
82 lines (70 loc) · 1.48 KB
/
plot4.R
File metadata and controls
82 lines (70 loc) · 1.48 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
####
#
# Author: Toby Patterson
# File: plot4.R
# Date: 7 August 2014
#
# Generates several graphs related to power generation.
# Presumes the file project1_datafile.Rda exists in the same directory.
#
####
# Read in the table data
# Note you may need to run generate_datafile.R if this file does not exist
data_file = 'project1_datafile.Rda'
if ( !file.exists(data_file)) {
stop('Run generate_datafile.R to create the project working datafile.')
}
# Setup output parameters
canvas_size = 480
png(
file="plot4.png",
height=canvas_size,
width=canvas_size
)
# Setup page for displaying four charts
par(mfrow = c(2, 2))
# Chart 1
plot(
data$DateTime,
data$Global_active_power,
xlab='',
ylab='Global Active Power',
type='l'
)
# Chart 2
plot(
data$DateTime,
data$Voltage,
xlab="datetime",
ylab="Voltage",
type="l",
)
# Chart 3
plot(
data$DateTime,
data$Sub_metering_1,
xlab='',
ylab='Energy sub metering',
type='n'
)
# Plot points
points(data$DateTime,data$Sub_metering_1,col='black',type='l')
points(data$DateTime,data$Sub_metering_2,col='red',type='l')
points(data$DateTime,data$Sub_metering_3,col='blue',type='l')
legend("topright",
col=c("black", "red", "blue"),
c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
lty=1
)
# Chart 4
plot(
data$DateTime,
data$Global_reactive_power,
xlab="datetime",
ylab="Global_reactive_power",
type = "l"
)
# Yes I do want this
mtext('generated by Toby Patterson, 7 Sept 2014',1,4,cex=.5)
# Detatch
dev.off()