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
24 lines (18 loc) · 773 Bytes
/
plot2.R
File metadata and controls
24 lines (18 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Load libraries
library(dplyr)
# Read the data file
fulldata <- read.table('./data/household_power_consumption.txt', header = TRUE,
sep = ";", na.strings = "?")
# Subset on dates of interest using dplyr filter()
subset <- filter(fulldata, Date == '1/2/2007' | Date == '2/2/2007')
# Convert date/time character strings to actual dates/times
subset$Time <- strptime(paste(subset$Date, subset$Time, sep = ' '),
'%d/%m/%Y %H:%M:%S')
subset$Date <- as.Date(subset$Date, '%d/%m/%Y')
# Plot 2
with(subset, plot(Time, Global_active_power,
ylab = 'Global Active Power (kilowatts)',
xlab = '', type = 'l'))
# Save the output to a png file
dev.copy(png, file = './figures/plot2.png')
dev.off()