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
33 lines (30 loc) · 1.35 KB
/
plot2.R
File metadata and controls
33 lines (30 loc) · 1.35 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
plot2 <- function(){
library(stringr) ## for str_c()
##Read outcome data
row_start = 66638
row_end = 69517
options(stringsAsFactors = FALSE)
filename <- "household_power_consumption.txt"
col_names = c("Date", "Time", "Global_active_power",
"Global_reactive_power", "Voltage", "Global_intensity",
"Sub_metering_1", "Sub_metering_2", "Sub_metering_3")
data <-read.table(filename,
header = FALSE,
sep = ";",
na.strings = "?",
skip = row_start - 1,
nrows = row_end - row_start + 1,
colClasses = c(rep("character",2),rep("numeric",7)),
col.names = col_names
)
# combine column 1 & 2 to generate correct time tag
t_string <- str_c(data$Date, " ", data$Time)
time_stamp <- strptime(t_string, format="%d/%m/%Y %H:%M:%S")
#Plot and Record
png(filename = "plot2.png",
width = 480, height = 480, units = "px",
bg = "white")
plot(time_stamp, data$Global_active_power, type = "l", col = "black",
xlab = "", ylab = "Global Active Power (Kilowatts)", main = "")
dev.off()
}