forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.R
92 lines (77 loc) · 1.73 KB
/
plot4.R
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
82
83
84
85
86
87
88
89
90
91
92
####################################################################################################
#
#+ Dataset download details are provided in the Data_Download.md
#+ Downloaded dataset is available in the folder "data"
#+ The downloaded dataset has been read, formatted, filtered and saved using format.And.Filter.R
#+ The filtered dataset is saved to the directory "data" and is named "dat.for.2days.RData"
#
####################################################################################################
#loading 2-day household energy usage data (2007-02-01 and 2007-02-02)
load(file = "./data/dat.for.2days.RData")
ls()
#+ plot-4
png(filename = "plot4.png",
width = 480, height = 480, units = "px")
par(mfrow = c(2, 2))
##################
#
#+plot-4.1
#
##################
with (dat.for.2days,
plot(datetime, Global_active_power, type="l", xlab="",
ylab="Global Active Power", main=""
)
)
##################
#
#plot-4.2
#
##################
with (dat.for.2days,
plot(
datetime, Voltage, type="l",
ylab="Voltage",
main=""
)
)
##################
#
#plot-4.3
#
##################
with (
dat.for.2days,
plot(datetime, Sub_metering_1, type="l", col="black", xlab="",
ylab="Energy sub metering", main="")
)
lines (
dat.for.2days$datetime,
dat.for.2days$Sub_metering_2,
col="red", xlab="",
ylab="", main=""
)
lines (
dat.for.2days$datetime,
dat.for.2days$Sub_metering_3,
col="blue", xlab="",
ylab="", main=""
)
# Add legend
legend(
"topright",
legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
col=c("black", "red", "blue"), lty=1
)
##################
#
#plot-4.4
#
##################
with (dat.for.2days,
plot(
datetime, Global_reactive_power, type="l",
main=""
)
)
dev.off()