forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.R
22 lines (17 loc) · 942 Bytes
/
plot4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# reading and subsetting the data which is supposed to be in the parent directory of the current dir
data<-read.table("../household_power_consumption.txt", sep=";", stringsAsFactors=F, header=T)
data<-data[data$Date=='1/2/2007' | data$Date=='2/2/2007',]
# processing
data$DateTime<-strptime(paste(data$Date, data$Time), format="%d/%m/%Y %H:%M:%S")
data$Sub_metering_1 <- as.numeric(data$Sub_metering_1)
data$Sub_metering_2 <- as.numeric(data$Sub_metering_2)
data$Sub_metering_3 <- as.numeric(data$Sub_metering_3)
# re-creating the plot
png("plot3.png", width=480, height=480)
plot(data$DateTime, data$Sub_metering_1, type="l",
ylab="Energy sub metering", xlab="")
points(data$DateTime, data$Sub_metering_2, type="l", col="red")
points(data$DateTime, data$Sub_metering_3, type="l", col="blue")
legend("topright", legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
col=c("black", "red", "blue"), lty=1)
dev.off()