forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlot4.R
22 lines (20 loc) · 1.17 KB
/
Plot4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
list.files() # Verify the existence of the archive
Power <- read.table("household_power_consumption.txt", header = TRUE, sep = ";",quote = "", comment.char = "", na.strings = "?")
head(Power)
dim(Power)
powerfeb <- subset(Power, Date == "1/2/2007" | Date == "2/2/2007")
powerfeb
Conctiempo <- paste(powerfeb$Date, powerfeb$Time)
Newtime<- strptime(Conctiempo, "%d/%m/%Y %H:%M:%S")
class(Newtime)
NewPowerfeb <- cbind(Newtime,powerfeb)
png("plot4.png", width = 480, height = 480)
par(mfcol = c(2, 2))
plot(Newtime, NewPowerfeb$Global_active_power, type = "l", xlab = "", ylab = "Global Active Power (kilowatts)")
plot(Newtime, NewPowerfeb$Sub_metering_1, type = "l", xlab = "", ylab = "Energy Submetering")
lines(Newtime, NewPowerfeb$Sub_metering_2, type ="l", col = "red")
lines(Newtime, NewPowerfeb$Sub_metering_3, type ="l", col = "blue")
legend("topright", legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty = 1, lwd = 2.5, col = c("black", "red", "blue"))
plot(Newtime, NewPowerfeb$Voltage, type = "l", xlab = "datetime", ylab = "Voltage")
plot(Newtime, NewPowerfeb$Global_reactive_power, type = "l", xlab = "datetime", ylab = "Glogal_reactive_power")
dev.off()