forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.r
36 lines (27 loc) · 1.11 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
#plot4
source('get_data.r')
#function to check if file is downloaded, and download and unzip if not, returns file name
#check get_data.r
fPowerD <- check_grab()
#function to extract the necessary data, convert time data, and dump it all in a data frame
#check get_data.r
df <- create_frame(fPowerD)
png('plot4.png', bg='transparent')
par(mfrow=c(2,2))
with(df,{
#plot 1 from plot2
plot(datetime, Global_active_power,type='l', ylab="Global Active Power (kilowatts)", xlab='')
#plot 2 Voltage over time
plot(datetime,Voltage, type='l')
#plot 3 from plot3
plot(datetime, Sub_metering_1, type='n', ylab="Energy sub metering", xlab='')
lines(df$datetime, df$Sub_metering_1)
lines(df$datetime, df$Sub_metering_2, col='red')
lines(df$datetime, df$Sub_metering_3, col='blue')
legend('topright', bty='n', lty=c(1,1), col=c('black','red','blue'),
legend = c('Sub_metering_1','Sub_metering_2','Sub_metering_3'))
#plot 4 Global Reactive Power over time
plot(datetime, Global_reactive_power, type='l')
box()
dev.off()
})