forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot2.R
29 lines (25 loc) · 738 Bytes
/
plot2.R
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
29
# Load sqldf to enable partial read of CSV
library(sqldf)
# Load tidyverse to work with tibbles
library(tidyverse)
# Load only records for 2007-02-01 and 2007-02-02
data <- read.csv.sql(
"household_power_consumption.txt",
sql = "select * from file where Date in ('1/2/2007', '2/2/2007')",
sep = ";"
)
# Convert to tibble
data <- as_tibble(data)
# Convert Date and Time columns into a datetime
data <- data %>%
unite("Date.Time", Date:Time) %>%
mutate(Date.Time = as.POSIXct(Date.Time, format = "%d/%m/%Y_%H:%M:%S"))
png(filename = "plot2.png", width = 480, height = 480)
plot(
data$Date.Time,
data$Global_active_power,
type = "l",
xlab = "",
ylab = "Global Active Power (kilowatts)"
)
dev.off()