-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot2.R
More file actions
19 lines (15 loc) · 819 Bytes
/
plot2.R
File metadata and controls
19 lines (15 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# read subset of the data
dataset <- read.table("data/household_power_consumption.txt", skip=grep("1/2/2007", readLines("data/household_power_consumption.txt")), nrows=3000, sep=';')
names(dataset) <- c('Date','Time','Global_active_power','Global_reactive_power', 'Voltage', 'Global_intensity', 'Sub_metering_1', 'Sub_metering_2' ,'Sub_metering_3')
# convert date & cut off the dates
dataset$DateTime <- paste(dataset$Date, dataset$Time)
dataset$DateTime <- as.POSIXct(strptime(dataset$DateTime, '%d/ %m/ %Y %H:%M:%S' ) )
data_subset <- dataset[ dataset$DateTime < '2007-02-03 00:00:00', ]
# plot 2
png(filename='plot2.png', width = 480, height = 480, bg = NA)
plot( data_subset$DateTime, data_subset$Global_active_power,
type = 'l',
xlab = '',
ylab = 'Global Active Power (kilowatts)'
)
dev.off()