forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot3.R
15 lines (14 loc) · 960 Bytes
/
plot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
df <- read.csv("./household_power_consumption.txt",sep=";",stringsAsFactors=FALSE)
red_df <- df[df$Date == '1/2/2007' | df$Date == '2/2/2007', ]
# View(df)
rm(df) # clear some memory up
red_df$Time <- strptime(paste(red_df$Date,red_df$Time),"%d/%m/%Y %H:%M:%S")
red_df$Date <- as.Date(red_df$Date,"%d/%m/%Y")
red_df <- transform(red_df,Sub_metering_1 = as.numeric(Sub_metering_1),Sub_metering_2 = as.numeric(Sub_metering_2),Sub_metering_3 = as.numeric(Sub_metering_3))
# View(red_df)
png("plot3.png",width=480,height=480,units="px")
plot(red_df$Time,red_df$Sub_metering_1,type="l",col="Black",xlab="",ylab="Energy sub metering",ylim=c(0,max(red_df$Sub_metering_1,red_df$Sub_metering_2,red_df$Sub_metering_3)))
lines(red_df$Time,red_df$Sub_metering_2,col="red",type="l")
lines(red_df$Time,red_df$Sub_metering_3,col="blue",type="l")
legend("topright",col=c("Black","Red","Blue"),legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),lty=c(1,1))
dev.off()