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
20 lines (14 loc) · 774 Bytes
/
Copy pathplot2.R
File metadata and controls
20 lines (14 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
library(sqldf)
# Read data file, selecting only those rows between 2007-02-01 and 2007-02-02.
data <- read.csv.sql(file = 'household_power_consumption.txt', sep = ';', header = TRUE, sql = "select * from file where Date = '1/2/2007' OR Date = '2/2/2007'")
# Setup date/time format.
dateFormat <- '%d/%m/%Y %H:%M:%S'
# Combine date and time columns into single field and convert to Date object.
data$DateTime <- as.POSIXlt(paste(data$Date, data$Time), format = dateFormat)
# Set margin spacing in plot.
par(mar = c(4, 4, 2, 2))
# Plot.
plot(data$DateTime, data$Global_active_power, type = 'l', xlab = '', ylab = 'Global Active Power (kilowatts)', cex.lab = 0.75, cex.axis = 0.8)
# Copy to png file.
dev.copy(png, file = 'plot2.png', width = 480, height = 480)
dev.off()