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
28 lines (22 loc) · 1 KB
/
plot3.R
File metadata and controls
28 lines (22 loc) · 1 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
# 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 3
with(subset, plot(Time, Sub_metering_1,
ylab = 'Energy sub metering',
xlab = '', type = 'l'))
with(subset, points(Time, Sub_metering_2, type = 'l', col = 'red'))
with(subset, points(Time, Sub_metering_3, type = 'l', col = 'blue'))
legend('topright', lty = 1, col = c('black', 'red', 'blue'),
legend = c('Sub_metering_1', 'Sub_metering_2', 'Sub_metering_3'))
# Save the output to a png file
dev.copy(png, file = './figures/plot3.png')
dev.off()