-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot4.R
69 lines (34 loc) · 2.06 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#get data
data.source <- read.table("household_power_consumption.txt", comment.char= "", sep= ";", na.strings= "?", skip= 66600, n= 3050)
#convert to data frame
data <- data.frame(data.source)
#subset data for date range
range <- subset(data, as.Date(V1) == '01/02/2007' | as.Date(V1) == '02/02/2007')
#date and time conversion
date <- as.character(range$V1)
time <- as.character(range$V2)
date.time <- paste(date, time)
date.time <- strptime(date.time, "%d/ %m/ %Y %H: %M: %S")
days <- weekdays(date.time, abbreviate=TRUE)
png(filename = "plot3.png",width = 480, height = 480)
plot (date.time,range$V7,type = "l", xlab = "", ylab = "Energy sub metering",col="black")
lines (date.time,range$V8,type = "l", xlab = "", ylab = "Energy sub metering",col="red")
lines (date.time,range$V9,type = "l", xlab = "", ylab = "Energy sub metering",col="blue")
legend("topright", lty = 1, col = c("black", "red", "blue"), legend = c("Sub_metering_1","Sub_metering_2", "Sub_metering_3"))
dev.off()
#date and time conversion
date <- as.character(range$V1)
time <- as.character(range$V2)
date.time <- paste(date, time)
date.time <- strptime(date.time, "%d/ %m/ %Y %H: %M: %S")
days <- weekdays(date.time, abbreviate=TRUE)
png(filename = "plot4.png",width = 480, height = 480)
par(mfrow=c(2,2))
plot(date.time, range$V3, ylab= "Global Active Power",xlab=" ", type= "l")
plot(date.time,range$V5,ylab="Voltage",xlab="datetime",type="l")
plot (date.time,range$V7,type = "l", xlab = "", ylab = "Energy sub metering",col="black")
lines (date.time,range$V8,type = "l", xlab = "", ylab = "Energy sub metering",col="red")
lines (date.time,range$V9,type = "l", xlab = "", ylab = "Energy sub metering",col="blue")
legend("topright", lty = 1, col = c("black", "red", "blue"), legend = c("Sub_metering_1","Sub_metering_2", "Sub_metering_3"))
plot(date.time,range$V4,ylab="Global_reactive_power",xlab="datetime",type="l")
dev.off()