forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
executable file
·29 lines (23 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
library(data.table)
# Where my git repo is, and my dataset
setwd("~/DataScienceCourse/4 Exploratory Data Analysis/project1")
# initialize the df
rawdata <- read.table("household_power_consumption.txt", sep=";", header=T, na.strings="?")
headers <- colnames(rawdata)
data <- rawdata[as.Date(rawdata[,1], "%d/%m/%Y") == as.Date('2007-02-01')
| as.Date(rawdata[,1], "%d/%m/%Y") == as.Date('2007-02-02'),]
names(data) <- headers
# convert Date to date class
DateTime <- paste(data$Date, data$Time)
data$Date <- as.POSIXct(DateTime,"%d/%m/%Y %H:%M:%S", tz="")
# 480x480 is the default for all the bitmap graphics devices
windows(480, 480)
plot(data$Date, data$Sub_metering_1, type="l", xlab="", ylab="Engergy sub metering",
main="Sub Metering")
points(data$Date, data$Sub_metering_2, type="l", col="red")
points(data$Date, data$Sub_metering_3, type="l", col="blue")
legend("topright", pch="_", col=c("black", "red", "blue"),
legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"))
# save to a file and close graphics device
dev.copy(png, file = "plot3.png")
dev.off()