forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.R
28 lines (23 loc) · 1.16 KB
/
plot4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
df <- read.table("/Users/stanleyku/Desktop/ExData_Plotting1/household_power_consumption.txt", header=TRUE, sep=";")
df$Date <- as.Date(df$Date, "%d/%m/%Y")
df$Global_active_power <- as.numeric(df$Global_active_power)/1000
#df$Time <- strptime(df$Time, "%H:%M:%S")
df$DateTime <- as.POSIXct(paste(df$Date, df$Time), format="%d/%m/%Y %H:%M:%S")
subset <- subset(df, Date >= as.Date("2007-02-01") & Date <= as.Date("2007-02-02"))
png(filename="/Users/stanleyku/Desktop/ExData_Plotting1/plot4.png")
par(mfrow = c(2,2))
plot(subset$DateTime, subset$Global_active_power, type="l",
xlab="", ylab="Global Active Power")
plot(subset$DateTime, subset$Voltage, type="l",
xlab="datetime", ylab="Voltage")
plot(subset$DateTime, subset$Sub_metering_1, type="l",
ylab="Energy sub metering",
xlab="")
lines(subset$DateTime, subset$Sub_metering_2, col="red")
lines(subset$DateTime, subset$Sub_metering_3, col="blue")
legend("topright", legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
col=c("black", "red", "blue"),
lty=1)
plot(subset$DateTime, subset$Global_reactive_power, type="l",
xlab="datetime", ylab="GLobal Reactive Power")
dev.off()