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
18 lines (16 loc) · 1.02 KB
/
plot3.R
File metadata and controls
18 lines (16 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#read table
powerConsumption <- read.table(file = "household_power_consumption.txt",sep = ";",header=TRUE,na.strings="?")
#format Date
powerConsumption$Date <- as.Date(powerConsumption$Date,"%d/%m/%Y")
#subset of data for dates 2007-02-01 & 2007-02-02
powerConsumptionSubset <- subset(powerConsumption,powerConsumption$Date == as.Date("2007-02-01") | powerConsumption$Date == as.Date("2007-02-02"))
#generating additional column datetime
powerConsumptionSubset$datetime <- as.POSIXct(paste(powerConsumptionSubset$Date, powerConsumptionSubset$Time), format="%Y-%m-%d %H:%M:%S")
#draw plot
with(powerConsumptionSubset,plot(datetime,Sub_metering_1,type="n",ylab="Energy sub metering",xlab=""))
with(powerConsumptionSubset,lines(datetime,Sub_metering_1))
with(powerConsumptionSubset,lines(datetime,Sub_metering_2,col="red"))
with(powerConsumptionSubset,lines(datetime,Sub_metering_3,col="blue"))
legend("topright",col=c("black","red","blue"),legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),lty=1)
dev.copy(png,file="plot3.png")
dev.off()