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
41 lines (28 loc) · 1.29 KB
/
plot3.R
File metadata and controls
41 lines (28 loc) · 1.29 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
38
39
40
#####################################
### Data input and manipulation #####
#####################################
setwd("~/R/courseraEDA/Project1")
data <- read.table("power.txt", #pre-extracted data for specified dates with grep
comment.char="#",sep=";",
stringsAsFactors = FALSE,
col.names = c("date","time","active","reactive","voltage","intensity","sm1","sm2","sm3"))
data$date <- as.Date(data$date,format="%d/%m/%Y") #convert date to Date class
dateTime <- paste(data$date,data$time,sep=",")
newDateTime <- strptime(dateTime,format='%Y-%m-%d,%H:%M:%S') #convert date & time to POSIXlt
#####################################
### Plot 3 ##########################
#####################################
png("plot3.png", # create PNG for the heat map
width = 480, # dimensions in pixels
height = 480,
)
plot(newDateTime,data$sm1, type = "l", #black line graph sm1
ylab ="Energy sub metering",xlab= "", #label axes
)
lines(newDateTime,data$sm2, type = "l", #red line graph sm2
col="red")
lines(newDateTime,data$sm3, type = "l", #blue line graph sm3
col="blue")
legendTxt <- c("sub_metering_1","sub_metering_2","sub_metering_3")
legend("topright",legendTxt,col = c("black", "red", "blue"),lty=1)
dev.off() # close the PNG device