forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot4.R
More file actions
21 lines (18 loc) · 1.43 KB
/
plot4.R
File metadata and controls
21 lines (18 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
data <- read.table("household_power_consumption.txt", header = T, sep = ";")
data$Date <- as.Date(data$Date, format = "%d/%m/%Y")
consumption <- data[(data$Date == "2007-02-01")|(data$Date == "2007-02-02"),]
consumption$Global_active_power <- as.numeric(as.character(consumption$Global_active_power))
consumption <- transform(consumption, fulltime=as.POSIXct(paste(Date, Time)), "%d/%m/%Y %H:%M:%S")
consumption$Sub_metering_1 <- as.numeric(as.character(consumption$Sub_metering_1))
consumption$Sub_metering_2 <- as.numeric(as.character(consumption$Sub_metering_2))
consumption$Sub_metering_3 <- as.numeric(as.character(consumption$Sub_metering_3))
png("plot4.png", width = 480, height=480)
par(mfrow = c(2, 2))
plot(consumption$fulltime, consumption$Global_active_power, type = "l", xlab ="", ylab = "Global Active Power")
plot(consumption$fulltime, consumption$Voltage, type = "l", xlab ="Date Time", ylab = "Voltage")
plot(consumption$fulltime, consumption$Sub_metering_1, type = "l", xlab = "", ylab = "Energy sub metering")
lines(consumption$fulltime, consumption$Sub_metering_2, col ="red")
lines(consumption$fulltime, consumption$Sub_metering_3, col ="blue")
legend("topright", c("Sub_metering_1","Sub_metering_2","Sub_metering_3"), lty = c(1, 1, 1), lwd = c(1, 1, 1), col = c("black", "red", "blue"))
plot(consumption$fulltime, consumption$Global_reactive_power, type = "l", xlab ="Date Time", ylab = "Global Reactive Power")
dev.off()