forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot4.R
25 lines (22 loc) · 1.19 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
Sys.setlocale("LC_TIME","en_US.UTF-8")
A <- read.table("household_power_consumption.txt",head=T,sep=";",stringsAsFactors=F)
A$Date <- as.Date(A$Date,"%d/%m/%Y")
B <- subset(A,A$Date>="2007-02-01" & A$Date<="2007-02-02")
B$Global_active_power <- as.numeric(B$Global_active_power)
B$Global_reactive_power <- as.numeric(B$Global_reactive_power)
B$Voltage <- as.numeric(B$Voltage)
B$Sub_metering_1 <- as.numeric(B$Sub_metering_1)
B$Sub_metering_2 <- as.numeric(B$Sub_metering_2)
B$Sub_metering_3 <- as.numeric(B$Sub_metering_3)
B$temp <- strptime(paste(B$Date,B$Time),"%Y-%m-%d %H:%M:%S")
png(filename="plot4.png",width=480, height=480, units ="px")
par(mfrow=c(2,2))
plot(B$temp, B$Global_active_power,type="l",xlab="", ylab="Global Active Power")
plot(B$temp, B$Voltage, type="l", xlab="datetime", ylab="Voltage")
plot(B$temp, B$Sub_metering_1,type="l",xlab="", ylab="Energy sub metering")
lines(B$temp, B$Sub_metering_2, col="red")
lines(B$temp, B$Sub_metering_3, col="blue")
legend("topright", c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),
col=c("black","red","blue"),lty=1,bty="n")
plot(B$temp, B$Global_reactive_power, type="l", xlab="datetime", ylab="Global_reactive_power")
dev.off()