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) · 951 Bytes
/
Copy pathplot3.R
File metadata and controls
28 lines (22 loc) · 951 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
26
27
# get data
nameOfData <- read.table("household_power_consumption.txt",
nrow=1,sep=";")
d <- read.table("household_power_consumption.txt",
skip=65500,nrow=5000,sep=";",na.strings = "?")
d$V1 <- as.Date(d$V1,format="%d/%m/%Y")
d$V2 <- as.character(d$V2)
names(d) <- unlist(nameOfData[1,])
library(dplyr)
d <- filter(d,Date>=as.Date("2007-02-01") & Date <= as.Date("2007-02-02"))
d <- mutate(d,datetime=paste(Date,Time,sep=" "))
d$datetime <- strptime(d$datetime,format = "%Y-%m-%d %H:%M:%S")
# plot
png(filename='plot3.png',width = 480,height = 480)
plot(d$datetime,d$Sub_metering_1,type = "n",xlab="",
ylab = "Energy sub metering")
lines(d$datetime,d$Sub_metering_1,col="black")
lines(d$datetime,d$Sub_metering_2,col="red")
lines(d$datetime,d$Sub_metering_3,col="blue")
legend("topright",lty = 1,col=c("black","red","blue"),
legend = c("Sub_metering_1","Sub_metering_2","Sub_metering_3"))
dev.off()