-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot4.R
14 lines (14 loc) · 1.02 KB
/
plot4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
datafile <- read.table(file="household_power_consumption.txt", sep = ";", header=T)
filter_data <- datafile[datafile$Date == "1/2/2007" | datafile$Date == "2/2/2007",]
t <- paste(filter_data$Date, filter_data$Time)
t <- strptime(t, "%d/%m/%Y %H:%M:%S")
png("plot4.png", width=480, height=480)
par(mfrow=c(2,2))
plot(as.numeric(t), as.numeric(filter_data$Global_active_power), type="l", xlab="", ylab="Global Active Power")
plot(as.numeric(t), as.numeric(filter_data$Voltage), type="l", xlab="datetime", ylab="Voltage")
plot(as.numeric(t), as.numeric(filter_data$Sub_metering_1), type="l", ylab="Enegry sub metering", xlab="")
lines(as.numeric(t), as.numeric(filter_data$Sub_metering_2), type="l", col="red")
lines(as.numeric(t), as.numeric(filter_data$Sub_metering_3), type="l", col="blue")
legend("topright", col=c("black", "red", "blue"), pch="-", legend=c("Sub_meterimg_1", "Sub_metering_2", "Sub_metering_3"))
plot(as.numeric(t), as.numeric(filter_data$Global_reactive_power), type="l", xlab="datetime", ylab="Global_reactive_power")
dev.off()