-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot4.R
More file actions
22 lines (22 loc) · 1.35 KB
/
plot4.R
File metadata and controls
22 lines (22 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
plot4 <- function(file){
file <- "household_power_consumption.txt"
tempData <- read.table(file, sep=";", header=TRUE, colClasses=rep("character",9))
data <- subset(tempData, tempData$Date == "2/2/2007" | tempData$Date == "1/2/2007")
timestamp <- strptime(paste(data$Date, data$Time, sep=" "), "%d/%m/%Y %H:%M:%S")
data$Global_active_power <- as.numeric(data$Global_active_power)
data$Global_reactive_power <- as.numeric(data$Global_reactive_power)
data$Voltage <- as.numeric(data$Voltage)
data$Sub_metering_1 <- as.numeric(data$Sub_metering_1)
data$Sub_metering_2 <- as.numeric(data$Sub_metering_2)
data$Sub_metering_3 <- as.numeric(data$Sub_metering_3)
png("plot4.png", height=480, width=480)
par(mfrow=c(2,2))
plot(timestamp, data$Global_active_power, type="l", xlab="", ylab="Global Active Power(kilowatts)")
plot(timestamp, data$Voltage, type="l", xlab="Datetime", ylab="Voltage")
plot(timestamp, data$Sub_metering_1, col="black", type="l", xlab="", ylab="Energy Sub-metering")
lines(timestamp, data$Sub_metering_2, col="red", type="l")
lines(timestamp, data$Sub_metering_3, col="blue", type="l")
legend("topright", c("Sub_metering_1","Sub_metering_2","Sub_metering_3"), lty=1, lwd=2, col=c("black","red","blue"))
plot(timestamp, data$Global_reactive_power, type="l", xlab="Datetime", ylab="Global Reactive Power(kilowatts)")
dev.off()
}