forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.R
39 lines (28 loc) · 962 Bytes
/
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
# This script renders the fourth plot
# remove all variables from the workspace
rm(list = ls())
# set the work directory
setwd("C:/Users/Rod/Documents/coursera/data-science/04_ExploratoryDataAnalysis/02-second-try/week_01/project/ExData_Plotting1")
# Import getData function
source('util.R')
message('Printing plot 4...')
data <- getData()
png('output/plot4.png', width=480, height=480, bg='transparent')
# 4 graphs, 2 per row.
par(mfrow=c(2,2))
# Plot the four graphs
with(data, {
plot(DateTime, Global_active_power, type='l', xlab='', ylab='Global Active Power')
})
with(data, {
plot(DateTime, Voltage, xlab='datetime', type='l')
})
with(data, {
plot(DateTime, Sub_metering_1, type='l', xlab='', ylab="Energy sub metering")
lines(DateTime, Sub_metering_2, type='l', col='red')
lines(DateTime, Sub_metering_3, type='l', col='blue')
})
with(data, {
plot(DateTime, Global_reactive_power, xlab='datetime', type='l')
})
dev.off()