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
40 lines (32 loc) · 1.43 KB
/
Copy pathplot4.R
File metadata and controls
40 lines (32 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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
data <- read.csv.sql("household_power_consumption.txt",sql = "select * from file where Date = '2/2/2007' or Date = '1/2/2007'",header = TRUE, sep = ";", stringsAsFactors=FALSE)
png('/Users/NidhiVyas/Desktop/datascience/plot4.png',width = 480, height = 480)
par(mfrow=c(2,2))
##graph 1 in first row/line
y <- data[,3]
lab <- c("Thu","Fri","Sat")
plot(1:2880, y,type="l",xaxt='n',xlab = "",ylab = "Global Active Power (kilowatts)")
axis(side=1, at=c(0,1440,2880), c("Thu","Fri","Sat"))
##graph 2 in first line
y <- data[,5]
lab <- c("Thu","Fri","Sat")
plot(1:2880, y,type="l",xaxt='n',xlab = "datetime",ylab = "Voltage")
axis(side=1, at=c(0,1440,2880), c("Thu","Fri","Sat"))
##number 3 and first in the second row
y <- data[,3]
lab <- c("Thu","Fri","Sat")
y1 <- data[,7]
y2 <- data[,8]
y3 <- data[,9]
plot(1:2880,y1,type="l",col="black",xaxt='n',xlab = "",ylab = "Energy sub metering")
points(1:2880,y2,col="red",type = "l")
points(1:2880,y3,col="blue", type = "l")
axis(side=1, at=c(0,1440,2880), c("Thu","Fri","Sat"))
legend("topright", 1.9, c("sub_metering_1", "sub_metering_2", "sub_metering_3"), col = c("black", "red", "blue"),
text.col = "black", lty = c(1, 1, 1), pch = c(NA, NA, NA),
merge = TRUE)
##plot number four and last in the second row
y <- data[,4]
lab <- c("Thu","Fri","Sat")
plot(1:2880, y,type="l",xaxt='n',xlab = "datetime",ylab = "Global_reactive_power")
axis(side=1, at=c(0,1440,2880), c("Thu","Fri","Sat"))
dev.off()