forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot1.R
More file actions
25 lines (19 loc) · 832 Bytes
/
plot1.R
File metadata and controls
25 lines (19 loc) · 832 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
25
# 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 1
with(subset, hist(subset$Global_active_power,
xlab = 'Global Active Power (kilowatts)',
ylab = 'Frequency', main = 'Global Active Power',
col = 'red'))
# Save the output to a png file
dev.copy(png, file = './figures/plot1.png')
dev.off()