forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot3.R
31 lines (24 loc) · 1.08 KB
/
plot3.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
30
31
## Load Libraries
library(tidyverse)
library(lubridate)
## Read data from local folder
hpc <- read.table("./household_power_consumption.txt",
header=TRUE, sep=";", na.strings = "?",
colClasses = c('character','character','numeric','numeric','numeric','numeric','numeric','numeric','numeric'))
## Convert character to date
hpc$Date <- hpc$Date %>% as.Date("%d/%m/%Y")
## Filter date
hpcanalysis <- hpc %>% filter(Date>="2007-2-1", Date<="2007-2-2") %>% drop_na()
## Create new column DateTime
hpcanalysis$DateTime <- paste(as.Date(hpcanalysis$Date), hpcanalysis$Time)
hpcanalysis$DateTime <- as.POSIXct(hpcanalysis$DateTime )
## plot3
with(hpcanalysis,
{plot(Sub_metering_1~DateTime, type="l",
ylab="Global Active Power (kilowatts)", xlab="")
lines(Sub_metering_2~DateTime,col='Red')
lines(Sub_metering_3~DateTime,col='Blue')})
legend("topright", col=c("black", "red", "blue"), lty=1, lwd=2,
legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
dev.copy(png, file="plot3.png", height=480, width=480)
dev.off()