forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot2.R
More file actions
38 lines (23 loc) · 1.22 KB
/
plot2.R
File metadata and controls
38 lines (23 loc) · 1.22 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
##########################################################################
### 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 2 Global Active Power over time ################################
##########################################################################
png("plot2.png", # create PNG for the heat map
width = 480, # dimensions in pixels
height = 480,
)
plot(newDateTime,data$active, type = "l", #line graph
ylab ="Global Active Power (kilowatts)",
xlab = "",
)
dev.off() # close the PNG device