forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3.R
More file actions
37 lines (30 loc) · 1.07 KB
/
plot3.R
File metadata and controls
37 lines (30 loc) · 1.07 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
source("load.R")
# Helper function for drawing the plot
do_plot3 <- function(hpc,frame=TRUE){
# Main plot and first series
plot(hpc$datetime,hpc$Sub_metering_1,type='l',xlab ="",ylab="Energy sub metering")
# Second series
lines(hpc$datetime,hpc$Sub_metering_2,col='red')
# Third series
lines(hpc$datetime,hpc$Sub_metering_3,col='blue')
# Add legend
if(frame==TRUE)
bty = 'y'
else
bty = 'n'
legend("topright",c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),lty=c(1,1),col=c('black','red','blue'),bty=bty)
}
# Wrapper function for taking care of loading data, output device, ...
# This is what you should call to view the result
plot3 <- function(hpc=NULL){
# Load Plot data
if(is.null(hpc)){
hpc<-load_data()
}
# Create PNG output device
png("plot3.png",width = 480, height = 480)
# Draw plot
do_plot3(hpc)
# Release output device
dev.off()
}