forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
46 lines (38 loc) · 985 Bytes
/
plot3.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
#plot3.R
#by Andrew Vallejos
#
# Run command for assignment
#> source("plot3.R");plot3("household_power_consumption.txt", png = T)
plot3 <- function(file, png = F){
#external function call to read and subset data
source("read_data.R")
data <- read_data(file)
#checks flag to open PNG device
#useful for testing to the screen device and then
#printing the graph to a file only when it looks good
if(png)
{
png("plot3.png", bg="transparent")
}
make_plot3(data);
#turns off external device if one was used
if(png)
{
dev.off();
}
}
make_plot3 <- function(data){
plot(data$timestamp,data$Sub_metering_1,
type = "l",
main = "",
xlab = "",
ylab = "Global Active Power (kilowatts)")
lines(data$timestamp,data$Sub_metering_2,
type = "l",
col = "red")
lines(data$timestamp,data$Sub_metering_3,
type = "l",
col = "blue")
legend("topright", legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
col=c("black","red","blue"), lty=1)
}