forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.R
19 lines (19 loc) · 871 Bytes
/
plot4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cp1file <- read.table("../household_power_consumption.txt", sep=";", header = TRUE)
df <- cp1file[cp1file$Date %in% c("2/2/2007", "1/2/2007"), ]
datetime <- paste(df$Date, df$Time)
x <- strptime(datetime, "%d/%m/%Y %H:%M:%S", tz="")
png(filename="plot4.png")
par(mfrow=c(2,2))
plot(x , df$Global_active_power, type = "l",
ylab = 'Global Active Power (kilowatts)', xlab = "")
plot(x , df$Voltage, type = "l",
ylab = 'Voltage', xlab = "datetime")
plot(x , df$Sub_metering_1, type = "l",
ylab = 'Energy sub metering', xlab = "")
lines(x, df$Sub_metering_3, col='blue')
lines(x, df$Sub_metering_2, col='red')
legend("topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
col = c('black', 'red', 'blue'), lty = 1, cex=0.6)
plot(x , df$Global_reactive_power, type = "l",
ylab = 'Global_reactive_power', xlab = "datetime")
dev.off()