-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plot4.R
19 lines (18 loc) · 1.18 KB
/
Plot4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
data <- read.csv("/household_power_consumption.txt", header=TRUE, sep=";", stringsAsFactors=FALSE, na.strings="?")
View(data)
head(data)
subData <- subset(data, as.Date(data$Date, format = "%d/%m/%Y")>= "2007-02-01" & as.Date(data$Date, format = "%d/%m/%Y") <= "2007-02-02" )
subData$Date<-as.Date(subData$Date,format = "%d/%m/%Y")
subData$dateTime <- as.POSIXct(paste(subData$Date, subData$Time, format= "%Y-%m-%d %H:%M:%S"))
par(mfrow = c(2,2))
with(subData, {
plot(subData$dateTime, subData$Global_active_power, type = "l", xlab = "", ylab = "Global Active Power(kilowatts)")
plot(subData$dateTime, subData$Voltage, type = "l", ylab = "Voltage", xlab = "datetime")
plot(subData$dateTime, subData$Sub_metering_1, type = "l", xlab = "", ylab = "Energy sub metering")
lines(subData$dateTime, subData$Sub_metering_2, col = "red", type = "l")
lines(subData$dateTime, subData$Sub_metering_3, col = "blue", type = "l")
legend("topright", col = c("black","red","blue"), lty = 1, legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"), bty = "n", cex=0.8)
plot(subData$dateTime, Global_reactive_power, type = "l", xlab = "datetime")
})
dev.copy(png, file = "plot4.png", width = 480,height = 480)
dev.off()